Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define llong long long
  4.  
  5. #define pb push_back
  6. #define mp make_pair
  7.  
  8. const int INF = (int) 1e9 + 7;
  9. const int MXN = (int) 1e2 + 7;
  10.  
  11. using namespace std;
  12.  
  13. const int dx[] = {1, -1, 2, -2, 1, -1, 2, -2};
  14. const int dy[] = {2, -2, 1, -1, -2, 2, -1, 1};
  15.  
  16. int t, n, m, cnt;
  17. int u[MXN][MXN];
  18.  
  19. bool dfs(int x, int y, int c = 1) {
  20. u[x][y] = true;
  21. bool boo = false;
  22. cout << x << ' ' << y << "\n";
  23. if (c == n * m) return true;
  24. for (int i = 0; i < 8; i++) {
  25. int nx = x + dx[i];
  26. int ny = y + dy[i];
  27. if (nx >= 1 && nx <= n && ny > 0 && ny <= m && !u[nx][ny])
  28. boo |= dfs(nx, ny, c + 1);
  29. }
  30. u[x][y] = false;
  31. return boo;
  32. }
  33.  
  34. int main() {
  35. #ifndef LOCAL
  36.  
  37. #define FN "binary"
  38. freopen(FN".in", "r", stdin);
  39. freopen(FN".out", "w", stdout);
  40.  
  41. #endif // LOCAL
  42.  
  43. scanf("%d", &t);
  44. for (int cases = 1; cases <= t; cases++) {
  45. scanf("%d%d", &n, &m);
  46. for (int i = 1; i <= n; i++)
  47. for (int j = 1; j <= m; j++)
  48. if (dfs(i, j)) printf("%c%d", char(i + 'A' - 1), j);
  49. }
  50. return 0;
  51. }
  52. //[(][([([[)])]([(][](]
  53. //[(][([(([[)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement