Advertisement
savrasov

123

Jun 6th, 2017
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7.  
  8. bool din[105][105], ma[105][105], used[105][105];
  9. int e[10] = {0, 0, 1, -1, 1, -1, 1, -1}, e1[10] = {1, -1, 0, 0, -1, 1, 1, -1};
  10.  
  11. int ch(int x, int y)
  12. {
  13. for(int i = 0; i < 8; i++)
  14. if(din[x + e[i]][y + e1[i]] && ma[x + e[i]][y + e1[i]]) return i;
  15. return 10;
  16. }
  17.  
  18. int main()
  19. {
  20. //freopen("input.txt", "r", stdin);
  21. //freopen("output.txt", "w", stdout);
  22. int n, m, x = -1, y = -1, d;
  23. string s;
  24. char t;
  25. cin >> n >> m;
  26. for(int i = 0; i < n; i++)
  27. {
  28. cin >> s;
  29. for(int j = 0; j < m; j++)
  30. {
  31. t = s[i];
  32. ma[i][j] = (t != '#');
  33. if(t == '#')
  34. for(int u = 0; u < 8; u++)
  35. if(i + e[u] > -1 && j + e1[u] > - 1) din[i + e[u]][j + e1[u]] = 1;
  36. }
  37. }
  38. for(int i = 0; i < n; i++)
  39. for(int j = 0; j < m; j++)
  40. if(din[i][j] && x != -1 && y != -1 && ma[i][j])
  41. {
  42. x = i;
  43. y = j;
  44. break;
  45. }
  46. while(ch(x, y) < 4)
  47. cout << x << ' ' << y << endl, d = ch(x, y), x += e[d], y += e1[d];
  48. if(x != -1 && y != -1) cout << x << " " << y;
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement