Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* b351 */
- /* AC (0.7s, 23.9MB) */
- #include <cstdio>
- #include <cstring>
- using namespace std;
- bool Sq[4999][4999];
- int t;
- int main()
- {
- scanf("%d", &t);
- while(t--)
- {
- for(int N, R, C; ~scanf("%d %d %d", &N, &R, &C);)
- {
- memset(Sq, false, sizeof(Sq));
- int cnt = 1, r = 0, c = N >> 1;
- const int Top = 0, Button = N - 1, Left = 0, Right = N - 1;
- --R, --C;
- Sq[r][c] = true;
- while(R != r || C != c)
- {
- ++cnt;
- if(r - 1 < Top)
- if(c - 1 < Left)
- Sq[++r][c] = true;
- else
- {
- int _c = c;
- while(_c >= Left && Sq[N - 1][--_c]);
- if(_c < Left)
- Sq[++r][++c] = true;
- else
- Sq[r = N - 1][c = _c] = true;
- }
- else if(c - 1 < Left)
- {
- int _r = r;
- while(_r >= Top && Sq[--_r][N - 1]);
- if(_r < Top)
- Sq[++r][++c] = true;
- else
- Sq[r = _r][c = N - 1] = true;
- }
- else
- if(Sq[r - 1][c - 1])
- {
- while(Sq[++r][c]);
- Sq[r][c] = true;
- }
- else
- Sq[--r][--c] = true;
- }
- printf("%d\n", cnt);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement