a53

horse

a53
Feb 28th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include<vector>
  3. #define DN 46345
  4. #define pb push_back
  5. #define x first
  6. #define y second
  7. #include<queue>
  8. using namespace std;
  9. ifstream fin("horse.in");
  10. ofstream fout("horse.out");
  11. int n,p,l,c,t,k,prl,prc,pr,a[DN];
  12.  
  13. int main()
  14. {
  15. fin>>n>>p;
  16. l=c=1;
  17. pr=p;
  18. if(p==n*n)
  19. {
  20. fout<<n/2+n%2<<' '<<n/2+n%2;
  21. return 0;
  22. }
  23. while(1)
  24. {
  25. if(4*n-4+4*(n-2)-4>=p)
  26. break;
  27. k+=2;
  28. p-=4*n-4+4*(n-2)-4;
  29. n-=4;
  30. }
  31. t=4*n-4+4*(n-2)-4;
  32. p--;
  33. while(p)
  34. {
  35. while(p&&c<n-1)
  36. {
  37. p--;
  38. c+=2;
  39. if(l==1)
  40. l=2;
  41. else
  42. l=1;
  43. }
  44. while(p&&l<n-1)
  45. {
  46. p--;
  47. l+=2;
  48. if(c==n)
  49. c=n-1;
  50. else
  51. c=n;
  52. }
  53. while(p&&c>2)
  54. {
  55. p--;
  56. c-=2;
  57. if(l==n)
  58. l=n-1;
  59. else
  60. l=n;
  61. }
  62. while(p&&l>2)
  63. {
  64. p--;
  65. l-=2;
  66. if(c==1)
  67. c=2;
  68. else
  69. c=1;
  70. }
  71. if(pr!=1&&l==1&&c==1)
  72. c=3;
  73. }
  74. cout<<n<<' '<<k;
  75. l+=k;
  76. c+=k;
  77. fout<<l<<' '<<c<<'\n';
  78. }
Advertisement
Add Comment
Please, Sign In to add comment