Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- using namespace std;
- const int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
- const int MAX = 101;
- int a[MAX][MAX];
- int main()
- {
- freopen("Input.txt", "r", stdin);
- freopen("Output.txt", "w", stdout);
- int n, m, p;
- cin >> n >> m >> p;
- memset(a, 0, sizeof(int) * MAX * MAX);
- int i = 0, j = 0, dir = 0;
- for (int pos = 0; pos < p; ++pos)
- {
- if (pos == p - 1)
- cout << i + 1 << ' ' << j + 1 << '\n';
- a[i][j] = pos + 1;
- if (i + d[dir][0] < 0 || i + d[dir][0] >= n || j + d[dir][1] < 0 || j + d[dir][1] >= m)
- dir = (dir + 1) % 4;
- if (a[i + d[dir][0]][j + d[dir][1]])
- dir = (dir + 1) % 4;
- i += d[dir][0], j += d[dir][1];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement