Korotkodul

Мун_2020_зеркала-ход слоном

Dec 4th, 2021 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <set>
  5. #include <string>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. void cv(vector <int> v){
  10. for (auto x: v) cout<<x<<' ';
  11. cout<<'\n';
  12. }
  13.  
  14. struct pnt{
  15. int x,y;
  16. char mr = 'Z';
  17. };
  18.  
  19. vector <pnt> way;
  20.  
  21. void cp(pnt x){
  22. //cout<<"xy= "<<x.x<<" "<<x.y<<"\n";
  23. //cout<<"mr= "<<x.mr<<"\n";
  24. cout<<x.x<<' '<<x.y<<' '<<x.mr<<"\n";
  25. }
  26.  
  27. bool cn(pnt a, pnt b){
  28. return (abs(a.x-b.x) == abs(a.y - b.y));
  29. }
  30. bool pos = 1;
  31.  
  32. int sgn(int a, int b){
  33. if (a - b < 0) return -1;
  34. else return 1;
  35. }
  36.  
  37. char mir(pnt fr, pnt to, pnt br){
  38. /*cout<<"sgn(br.x, fr.x)= "<<sgn(br.x, fr.x)<<"\n";
  39. cout<<"sgn(br.x, to.x)= "<<sgn(br.x, to.x)<<"\n";
  40.  
  41. cout<<"sgn(br.y, fr.y)= "<<sgn(br.y, fr.y)<<"\n";
  42. cout<<"sgn(br.y, to.y)= "<<sgn(br.y, to.y)<<"\n";*/
  43.  
  44. if (sgn(br.x, fr.x) == sgn(br.x, to.x)){
  45. //cout<<"return 'V';\n";
  46. return 'V';
  47. }
  48. else {
  49. //cout<<"return 'H';\n";
  50. return 'H';
  51. }
  52. }
  53.  
  54. void brg(pnt fr, pnt to){
  55. if (cn(fr, to)){
  56. // cout<<"cn(fr, to\n";
  57. return;
  58. }
  59. pnt thr;
  60. thr.y = to.y;
  61. thr.x = fr.x + (-fr.y + thr.y);
  62.  
  63. /*cout<<"thr\n";
  64. cp(thr);*/
  65. pnt br;
  66. br.x = (thr.x + to.x) / 2;
  67. //cout<<"(thr.x + to.x) / 2 = "<<(thr.x + to.x) / 2<<"\n";
  68. br.y = to.y + (to.x - br.x);
  69.  
  70. br.mr = mir(fr, to, br);
  71. /*cout<<"to\n";
  72. cp(to);
  73. cout<<"br\n";
  74. cp(br);
  75. cout<<"can???\n";
  76. cout<<"abs(br.x-to.x) "<<abs(br.x-to.x)<<"\n";
  77. cout<<"abs(br.y - to.y)= "<<abs(br.y - to.y)<<"\n";*/
  78. if (!cn(br, to) || !cn(br, fr)){
  79. //cout<<"CANNOT\n";
  80. pos = 0;
  81. }
  82. way.push_back(br);
  83. }
  84.  
  85.  
  86. int main()
  87. {
  88. /*ios::sync_with_stdio(0);
  89. cin.tie(0);
  90. cout.tie(0);*/
  91.  
  92. pnt a,b;
  93. int x2,y2;
  94. cin>>x2>>y2;//why?
  95. a = {0, 0};
  96. b = {x2, y2};
  97. brg(a, b);
  98. //cout<<"pos= "<<pos<<"\n";
  99. if (!pos){
  100. cout<<-1<<"\n";
  101. }else{
  102. if (way.empty()){
  103. cout<<0<<"\n";
  104. }else{
  105. cout<<way.size()<<"\n";
  106. cp(way[0]);
  107. }
  108. }
  109. }
  110. /*
  111. -10 -10 10 -8
  112. 0 0 5 1
  113. 0 0 -1 2
  114. 0 0 3 5
  115. 0 0 9 -1
  116. */
  117.  
Add Comment
Please, Sign In to add comment