matheus_monteiro

Arte Valiosa

Sep 18th, 2021 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ii pair<int, int>
  5. #define X first
  6. #define Y second
  7.  
  8. int n, m, k;
  9.  
  10. vector<int> G[2000];
  11. int cor[2000], tempo = 1;
  12.  
  13. bool check(ii c1, ii c2, int r1, int r2) {
  14.     return (c1.X - c2.X) * (c1.X - c2.X) + (c1.Y - c2.Y) * (c1.Y - c2.Y) <= (r1 + r2) * (r1 + r2);
  15. }
  16.  
  17. vector<int> border(ii c, int r) {
  18.     int x = c.X, y = c.Y;
  19.     vector<int> b;
  20.     if(x - r <= 0) b.push_back(k);
  21.     if(x + r >= n) b.push_back(k + 1);
  22.     if(y + r >= m) b.push_back(k + 2);
  23.     if(y - r <= 0) b.push_back(k + 3);
  24.     return b;
  25. }
  26.  
  27. void dfs(int v) {
  28.     cor[v] = tempo;
  29.     for(int &w : G[v])
  30.         if(cor[w] < tempo)
  31.             dfs(w);
  32. }
  33.  
  34. int32_t main() {
  35.     vector<ii> centers;
  36.     vector<int> raios;
  37.    
  38.     scanf(" %d %d %d", &n, &m, &k);
  39.    
  40.     for(int i = 0; i < k; i++) {
  41.         int x, y, r;
  42.         scanf(" %d %d %d", &x, &y, &r);
  43.         centers.push_back({x, y});
  44.         raios.push_back(r);
  45.     }
  46.     for(int i = 0; i < k; i++) {
  47.         for(int j = i + 1; j < k; j++)
  48.             if(check(centers[i], centers[j], raios[i], raios[j])) {
  49.                 G[i].push_back(j);
  50.                 G[j].push_back(i);
  51.             }
  52.         vector<int> b = border(centers[i], raios[i]);
  53.         for(int &w : b) {
  54.             G[w].push_back(i);
  55.             G[i].push_back(w);
  56.         }
  57.     }
  58.    
  59.     bool fl = true;
  60.    
  61.     tempo++;
  62.     dfs(k);
  63.     if(cor[k + 1] == tempo)
  64.         fl = false;
  65.  
  66.     tempo++;
  67.     dfs(k + 1);
  68.     if(cor[k + 2] == tempo or cor[k] == tempo)
  69.         fl = false;
  70.    
  71.     tempo++;
  72.     dfs(k + 2);
  73.     if(cor[k + 1] == tempo or cor[k + 3] == tempo)
  74.         fl = false;
  75.    
  76.     tempo++;
  77.     dfs(k + 3);
  78.     if(cor[k + 2] == tempo or cor[k] == tempo)
  79.         fl = false;
  80.    
  81.     puts(fl ? "S" : "N");
  82.    
  83.     return 0;
  84. }
Add Comment
Please, Sign In to add comment