Advertisement
tien_noob

Knight - Hương

Aug 19th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. //Make CSP great again
  2. #include <bits/stdc++.h>
  3. #define TASK "TESTCODE"
  4. using namespace std;
  5. const int N = 5e2;
  6. bool Visited[N + 1][N + 1];
  7. int dx[] = {1, 1, -1, -1, 2, 2, -2, -2};
  8. int dy[] = {2, -2, 2, -2, 1, -1, 1, -1};
  9. int n;
  10. int res = 0;
  11. void DFS(int i, int j)
  12. {
  13.     Visited[i][j] = true;
  14.     ++res;
  15.     for (int k = 0; k < 8; ++ k)
  16.     {
  17.         int x = dx[k] + i, y = dy[k] + j;
  18.         if (x > 0 && x <= n && y > 0 && y <= n && Visited[x][y] == false)
  19.         {
  20.             DFS(x, y);
  21.         }
  22.     }
  23. }
  24. void read()
  25. {
  26.     int x, y;
  27.     cin >> n >> x >> y;
  28.     DFS(x, y);
  29. }
  30. void solve()
  31. {
  32.     cout << res;
  33. }
  34. int main()
  35. {
  36.     ios_base::sync_with_stdio(false);
  37.     cin.tie(nullptr);
  38.     if (fopen(TASK".INP", "r"))
  39.     {
  40.         freopen(TASK".INP", "r", stdin);
  41.         //freopen(TASK".OUT", "w", stdout);
  42.     }
  43.     int t = 1;
  44.     bool typetest = false;
  45.     if (typetest)
  46.     {
  47.         cin >> t;
  48.     }
  49.     for (int __ = 1; __ <= t; ++ __)
  50.     {
  51.         read();
  52.         solve();
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement