Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. const int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  7. const int MAX = 101;
  8.  
  9. int a[MAX][MAX];
  10.  
  11. int main()
  12. {
  13. freopen("Input.txt", "r", stdin);
  14. freopen("Output.txt", "w", stdout);
  15.  
  16. int n, m, p;
  17. cin >> n >> m >> p;
  18.  
  19. memset(a, 0, sizeof(int) * MAX * MAX);
  20. int i = 0, j = 0, dir = 0;
  21. for (int pos = 0; pos < p; ++pos)
  22. {
  23. if (pos == p - 1)
  24. cout << i + 1 << ' ' << j + 1 << '\n';
  25. a[i][j] = pos + 1;
  26. if (i + d[dir][0] < 0 || i + d[dir][0] >= n || j + d[dir][1] < 0 || j + d[dir][1] >= m)
  27. dir = (dir + 1) % 4;
  28. if (a[i + d[dir][0]][j + d[dir][1]])
  29. dir = (dir + 1) % 4;
  30. i += d[dir][0], j += d[dir][1];
  31. }
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement