Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<string>
  6. #include<vector>
  7. #include<iterator>
  8. using namespace std;
  9. int a, i, sost, m, j, b, c, n, d, res = 0;
  10. vector<vector<char>>str;
  11. vector<vector<int>>vec;
  12. void rek(int x, int y) {
  13. if (x - 1 >= 0) {
  14. if (str[x - 1][y] != '#' &&
  15. (vec[x - 1][y] == 0
  16. || vec[x - 1][y] > vec[x][y] + 1)) {
  17. vec[x-1][y] = vec[x][y] + 1;
  18. rek(x - 1, y);
  19. }
  20. }
  21. if (y - 1 >= 0) {
  22. if (str[x][y - 1] != '#' && (vec[x][y - 1] == 0 || vec[x][y - 1] > vec[x][y] + 1)) {
  23. vec[x][y - 1] = vec[x][y] + 1;
  24. rek(x, y - 1);
  25. }
  26. }
  27. if (x + 1 < n) {
  28. if (str[x + 1][y] != '#' && (vec[x + 1][y] == 0 || vec[x + 1][y] > vec[x][y] + 1)) {
  29. vec[x + 1][y] = vec[x][y] + 1;
  30. rek(x + 1, y);
  31. }
  32. }
  33. int k = y;
  34. if (k < m - 1) {
  35. k++;
  36. if (int(str[x][k]) == int('.'))
  37. if(vec[x][k] == 0
  38. || vec[x][k] > vec[x][k-1] + 1) {
  39. vec[x][k] = vec[x][k-1] + 1;
  40. rek(x, k);
  41. }
  42. }
  43. }
  44. int main(){
  45. int k;
  46. cin >> n >> m >> k;
  47. vec.resize(n);
  48. str.resize(n);
  49. for (i = 0; i < n; ++i) {
  50. str[i].resize(m);
  51. for (int j = 0; j < m;++j)cin >> str[i][j];
  52. vec[i].resize(m);
  53. }
  54. cin >> i >> j >> a >> b;
  55.  
  56. rek(i-1, j-1);
  57. cout << vec[a][b];
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement