Advertisement
AdamTheGreat

Untitled

Sep 2nd, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct Point {
  7.     int x;
  8.     int y;
  9.     Point(int x, int y) : x(x), y(y) {}
  10. };
  11.  
  12. bool notempty(vector<queue<Point> > notebook) {
  13.     for (int i = 0; i < notebook.size(); i++) {
  14.         if (!notebook[i].empty()) {
  15.             return true;
  16.         }
  17.     }
  18.     return false;
  19. }
  20.  
  21. int main(void) {
  22.     int n, m, a, b;
  23.     cin >> n >> m >> a >> b;
  24.     vector<Point> leaders, infected;
  25.     vector<queue<Point> > notebooks;
  26.     for (int i = 0; i < a; i++) {
  27.         int x, y;
  28.         cin >> x >> y;
  29.         leaders.push_back(Point(x, y));
  30.     }
  31.     for (int i = 0; i < b; i++) {
  32.         int x, y;
  33.         cin >> x >> y;
  34.         infected.push_back(Point(x-1, y-1));
  35.         notebooks.push_back(queue<Point>());
  36.         notebooks[i].push(Point(x-1, y-1));
  37.     }
  38.     int dist[n][m];
  39.     for (int i = 0; i < n; i++) {
  40.         for (int j = 0; j < m; j++) {
  41.             dist[i][j] = 500000;
  42.         }
  43.     }
  44.     cout << "Here!" << endl;
  45.     int dirx[4] = {1, 0, -1, 0}, diry[4] = {0, 1, 0, -1};
  46.     // print out the distance from each leader to the closest infected
  47.     while (notempty(notebooks)) {
  48.         cout << "There!" << endl;
  49.         for (int i = 0; i < b; i++) {
  50.             Point current = notebooks[i].front();
  51.             cout << "Here & There!" << current.x << current.y << endl;
  52.             notebooks[i].pop();
  53.             for (int j = 0; j < 4; j++) {
  54.                 cout << "Hello World!" << i << j << endl;
  55.                 int newx = current.x + dirx[j];
  56.                 int newy = current.y + diry[j];
  57.                 if (newx >= 0 && newx < n && newy >= 0 && newy < m && dist[current.x][current.y] + 1 < dist[newx][newy]) {
  58.                     dist[newx][newy] = dist[current.x][current.y] + 1;
  59.                     notebooks[i].push(Point(newx, newy));
  60.                 }
  61.             }
  62.         }
  63.     }
  64.     for (int i = 0; i < a; i++) {
  65.         cout << dist[leaders[i].x][leaders[i].y] << endl;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement