Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <unordered_map>
  10. #include <unordered_set>
  11. #include <cmath>
  12. #include <ctime>
  13. #include <string>
  14. using namespace std;
  15.  
  16. #ifdef LOCAL
  17.     #define eprintf(...) fprintf(stderr, __VA_ARGS__)
  18. #else
  19.     #define eprintf(...) 42
  20. #endif
  21.  
  22. const int N = 30;
  23. int table[N][N];
  24. int n = 19;
  25. bool flag;
  26. int cntMove;
  27.  
  28. int dx, dy;
  29.  
  30. void init()
  31. {
  32.     for (int x = 1; x <= n; x++)
  33.         for (int y = 1; y <= n; y++)
  34.             table[x][y] = -1;
  35.     return;
  36. }
  37.  
  38. void move(int x, int y)
  39. {
  40.     if (flag)
  41.         swap(x, y);
  42.     if (table[x][y] != -1) return;
  43.     table[x][y] = 1;
  44.     cout << x << ' ' << y << endl;
  45.     return;
  46. }
  47.  
  48. void doSmart(int cntMove)
  49. {
  50.     int x = 10, y = 10;
  51.     while (table[x][y] == 0)
  52.     {
  53.         x += dx;
  54.         y += dy;
  55.     }
  56.  
  57.     move(x, y);
  58.  
  59.     dx *= -1;
  60.     dy *= -1;
  61.  
  62.     return;
  63. }
  64.  
  65. void makeMove(int cntMove)
  66. {
  67.     int x, y;
  68.     cin >> x >> y;
  69.     if (x == -1 && y == -1)
  70.         exit(0);
  71.     table[x][y] = 0;
  72.  
  73.     if (cntMove == 2)
  74.     {
  75.         dx = x - 10;
  76.         dy = y - 10;
  77.         if (dx == 1 && dy == 1)
  78.         {
  79.             dx = -1;
  80.             dy = -1;
  81.         }
  82.     }
  83.     if (cntMove == 5)
  84.     {
  85.         if (x == 3 && y == 6)
  86.             flag = true;
  87.     }
  88.  
  89.     if (cntMove == 3 || cntMove == 4)
  90.     {
  91.         doSmart(cntMove);
  92.         return;
  93.     }
  94.  
  95.     if (cntMove == 1)
  96.         move(5, 4);
  97.     else if (cntMove == 2)
  98.         move(4, 5);
  99.     else if (cntMove == 5)
  100.         move(3, 6);
  101.     else if (cntMove == 6)
  102.         move(3, 5);
  103.     else if (cntMove == 7)
  104.         move(3, 4);
  105.     else if (cntMove == 8)
  106.         move(5, 6);
  107.     else if (cntMove == 9)
  108.         move(5, 5);
  109.     else if (cntMove == 10)
  110.         move(4, 3);
  111.     else if (cntMove == 11)
  112.         move(6, 5);
  113.     else if (cntMove == 12)
  114.         move(7, 6);
  115.     else if (cntMove == 13)
  116.     {
  117.         move(8, 7);
  118.         move(3, 2);
  119.     }
  120.     else
  121.         throw;
  122.  
  123. }
  124.  
  125. int main()
  126. {
  127.     init();
  128.  
  129.     while(true)
  130.     {
  131.         cntMove++;
  132.         makeMove(cntMove);
  133.     }
  134.  
  135.     return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement