Advertisement
Emiliatan

b351

Apr 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. /* b351              */
  2. /* AC (0.7s, 23.9MB) */
  3. #include <cstdio>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. bool Sq[4999][4999];
  9. int t;
  10.  
  11. int main()
  12. {
  13.     scanf("%d", &t);
  14.     while(t--)
  15.     {
  16.         for(int N, R, C; ~scanf("%d %d %d", &N, &R, &C);)
  17.         {
  18.             memset(Sq, false, sizeof(Sq));
  19.             int cnt = 1, r = 0, c = N >> 1;
  20.             const int Top = 0, Button = N - 1, Left = 0, Right = N - 1;
  21.             --R, --C;
  22.             Sq[r][c] = true;
  23.             while(R != r || C != c)
  24.             {
  25.                 ++cnt;
  26.                 if(r - 1 < Top)
  27.                     if(c - 1 < Left)
  28.                         Sq[++r][c] = true;
  29.                     else
  30.                     {
  31.                         int _c = c;
  32.                         while(_c >= Left && Sq[N - 1][--_c]);
  33.                         if(_c < Left)
  34.                             Sq[++r][++c] = true;
  35.                         else
  36.                             Sq[r = N - 1][c = _c] = true;
  37.                     }
  38.                 else if(c - 1 < Left)
  39.                 {
  40.                     int _r = r;
  41.                     while(_r >= Top && Sq[--_r][N - 1]);
  42.                     if(_r < Top)
  43.                         Sq[++r][++c] = true;
  44.                     else
  45.                         Sq[r = _r][c = N - 1] = true;
  46.                 }
  47.                 else
  48.                     if(Sq[r - 1][c - 1])
  49.                     {
  50.                         while(Sq[++r][c]);
  51.                         Sq[r][c] = true;
  52.                     }
  53.                     else
  54.                         Sq[--r][--c] = true;
  55.             }
  56.             printf("%d\n", cnt);
  57.         }
  58.     }
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement