Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long size, a, b, cnt=1, cntmax=0;
  6. int vtx[8]={-2, -1, 1, 2, 2, 1, -1, -2},
  7. vty[8]={1 , 2 , 2, 1, -1, -2, -2, -1};
  8. bool used[505][505];
  9.  
  10. void init()
  11. {
  12. for(int i=0; i<=504; i++)
  13. {
  14. for(int j=0; j<=504; j++)
  15. {
  16. used[i][j]=true;
  17. }
  18. }
  19. for(int i=1; i<=size; i++)
  20. {
  21. for(int j=1; j<=size; j++)
  22. {
  23. used[i][j]=false;
  24. }
  25. }
  26. used[a][b]=true;
  27. }
  28.  
  29. //back//
  30. void back(int i)
  31. {
  32. for(int j=0; j<=7; j++)
  33. {
  34. if((a+vtx[j]>0&&b+vty[j]>0&&a+vtx[j]<=size&&b+vty[j]<=size)&&used[a+vtx[j]][b+vty[j]]==false)
  35. {
  36. a+=vtx[j];
  37. b+=vty[j];
  38. used[a][b]=true;
  39. //cout<<a<<" "<<b<<" "<<endl;
  40. back(i+1);
  41. used[a][b]=false;
  42. a-=vtx[j];
  43. b-=vty[j];
  44. }
  45. }
  46. //cout<<i<<endl;
  47. if(i>cntmax)
  48. {
  49. cntmax=i;
  50. }
  51. }
  52.  
  53. int main()
  54. {
  55. cin>>size>>a>>b;
  56. init();
  57. back(1);
  58. cout<<cntmax;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement