botgob

k=0

Mar 18th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <queue>
  5.  
  6. using namespace std;
  7.  
  8. class Node {
  9. public:
  10.     int x, y, ln, k;
  11.     Node();
  12. };
  13. Node::Node() {
  14.  
  15. }
  16.  
  17. bool vis[100][100];
  18. char mp[100][100];
  19. int main() {
  20.     for (int i = 0; i < 100; i++) {
  21.         for (int j = 0; j < 100; j++) {
  22.             mp[i][j] = false;
  23.         }
  24.     }
  25.     Node p;
  26.     p.x = 0;
  27.     p.y = 0;
  28.     p.ln = 0;
  29.     p.k = 0;
  30.     int y = 0;
  31.     int x = 0;
  32.     int e = 0;
  33.     int tot = 0;
  34.     cin >> y >> x >> e;
  35.     for (int i = 0; i < y; i++) {
  36.         string tmp = "";
  37.         cin >> tmp;
  38.         for (int j = 0; j < x; j++) {
  39.             mp[i][j] = tmp[j];
  40.         }
  41.     }
  42.    
  43.     queue<Node> q;
  44.     q.push(p);
  45.     while (!q.empty() && vis[y - 1][x - 1] == false) {
  46.         Node curr = q.front();
  47.         q.pop();
  48.         if (curr.x + 1 < x && mp[curr.y][curr.x + 1] != '#' && vis[curr.y][curr.x + 1] == false) {
  49.             Node next;
  50.             next.x = curr.x + 1;
  51.             next.y = curr.y;
  52.             next.ln = curr.ln + 1;
  53.             tot = curr.ln + 1;
  54.             q.push(next);
  55.             vis[curr.y][curr.x + 1] = true;
  56.         }
  57.         if (curr.y + 1 < y && mp[curr.y + 1][curr.x] != '#' && vis[curr.y + 1][curr.x] == false) {
  58.             Node next;
  59.             next.x = curr.x;
  60.             next.y = curr.y + 1;
  61.             next.ln = curr.ln + 1;
  62.             tot = curr.ln + 1;
  63.             q.push(next);
  64.             vis[curr.y + 1][curr.x] = true;
  65.         }
  66.         if (curr.x - 1 >= 0 && mp[curr.y][curr.x - 1] != '#' && vis[curr.y][curr.x - 1] == false) {
  67.             Node next;
  68.             next.x = curr.x - 1;
  69.             next.y = curr.y;
  70.             next.ln = curr.ln + 1;
  71.             tot = curr.ln + 1;
  72.             q.push(next);
  73.             vis[curr.y][curr.x - 1] = true;
  74.         }
  75.         if (curr.y - 1 >= 0 && mp[curr.y - 1][curr.x] != '#' && vis[curr.y - 1][curr.x] == false) {
  76.             Node next;
  77.             next.x = curr.x;
  78.             next.y = curr.y - 1;
  79.             next.ln = curr.ln + 1;
  80.             tot = curr.ln + 1;
  81.             q.push(next);
  82.             vis[curr.y - 1][curr.x] = true;
  83.         }
  84.     }
  85.    
  86.     if (vis[y - 1][x - 1] == false) {
  87.         cout << "nej";
  88.     } else {
  89.         cout << tot;
  90.     }
  91. #ifdef _DEBUG
  92.     system("pause");
  93. #endif // _DEBUG
  94. }
Advertisement
Add Comment
Please, Sign In to add comment