Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- typedef long long ll;
- bool din[105][105], ma[105][105], used[105][105];
- int e[10] = {0, 0, 1, -1, 1, -1, 1, -1}, e1[10] = {1, -1, 0, 0, -1, 1, 1, -1};
- int ch(int x, int y)
- {
- for(int i = 0; i < 8; i++)
- if(din[x + e[i]][y + e1[i]] && ma[x + e[i]][y + e1[i]]) return i;
- return 10;
- }
- int main()
- {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- int n, m, x = -1, y = -1, d;
- string s;
- char t;
- cin >> n >> m;
- for(int i = 0; i < n; i++)
- {
- cin >> s;
- for(int j = 0; j < m; j++)
- {
- t = s[i];
- ma[i][j] = (t != '#');
- if(t == '#')
- for(int u = 0; u < 8; u++)
- if(i + e[u] > -1 && j + e1[u] > - 1) din[i + e[u]][j + e1[u]] = 1;
- }
- }
- for(int i = 0; i < n; i++)
- for(int j = 0; j < m; j++)
- if(din[i][j] && x != -1 && y != -1 && ma[i][j])
- {
- x = i;
- y = j;
- break;
- }
- while(ch(x, y) < 4)
- cout << x << ' ' << y << endl, d = ch(x, y), x += e[d], y += e1[d];
- if(x != -1 && y != -1) cout << x << " " << y;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement