Advertisement
pb_jiang

abc259 d

Jul 9th, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. using ll = long long;
  6. using pii = pair<ll, ll>;
  7. using p3i = pair<pii, ll>;
  8.  
  9. int n, sx, sy, tx, ty;
  10. vector<p3i> cs;
  11.  
  12. vector<int> fa;
  13. void init(int n) { fa = vector<int>(n, -1); }
  14. int find(int x)
  15. {
  16.     if (fa[x] == -1)
  17.         return x;
  18.     return fa[x] = find(fa[x]);
  19. }
  20. int join(int x, int y)
  21. {
  22.     int px = find(x);
  23.     int py = find(y);
  24.     if (px == py) {
  25.         return px;
  26.     }
  27.     return fa[py] = px;
  28. }
  29.  
  30. long double epsilon = 1e-7;
  31. long double dist(ll x1, ll y1, ll x2, ll y2)
  32. {
  33.     long double dx = (long double) (x1) -x2;
  34.     long double dy = (long double) (y1) -y2;
  35.     return sqrt(dx * dx + dy * dy);
  36. }
  37.  
  38. ll dist_sq(ll x1, ll y1, ll x2, ll y2)
  39. {
  40.     ll dx = x1 - x2;
  41.     ll dy = y1 - y2;
  42.     return dx * dx + dy * dy;
  43. }
  44. bool pts_on_cirle(ll x, ll y, const p3i &c)
  45. {
  46.     // return abs(dist(x, y, c.first.first, c.first.second) - c.second) <= epsilon;
  47.     return dist_sq(x, y, c.first.first, c.first.second) == c.second * c.second;
  48. }
  49.  
  50. bool circles_sect(const p3i &c1, const p3i &c2)
  51. {
  52.     ll x1 = c1.first.first, y1 = c1.first.second, x2 = c2.first.first, y2 = c2.first.second;
  53.     /*
  54.     long double r1 = c1.second, r2 = c2.second;
  55.     if (dist(x1, y1, x2, y2) > r1 + r2 + epsilon) {
  56.         return false;
  57.     }
  58.     if (dist(x1, y1, x2, y2) + epsilon < abs(r1 - r2)) {
  59.         return false;
  60.     }
  61.     return true;
  62.     */
  63.     ll r1 = c1.second, r2 = c2.second;
  64.     if (dist_sq(x1, y1, x2, y2) > (r1 + r2) * (r1 + r2)) {
  65.         return false;
  66.     }
  67.     if (dist_sq(x1, y1, x2, y2) < (r1 - r2) * (r1 - r2)) {
  68.         return false;
  69.     }
  70.     return true;
  71. }
  72.  
  73. int main(int argc, char **argv)
  74. {
  75.     scanf("%d", &n);
  76.     cs = vector<p3i>(n + 1);
  77.     scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
  78.     ll x, y, r;
  79.  
  80.     for (int i = 0; i < n; ++i) {
  81.         scanf("%lld%lld%lld", &x, &y, &r);
  82.         cs[i] = {{x, y}, r};
  83.     }
  84.     init(n);
  85.     int fs = -1, ft = -1;
  86.     for (int i = 0; i < n; ++i) {
  87.         if (pts_on_cirle(sx, sy, cs[i]))
  88.             fs = i;
  89.         if (pts_on_cirle(tx, ty, cs[i]))
  90.             ft = i;
  91.         for (int j = i + 1; j < n; ++j) {
  92.             if (circles_sect(cs[i], cs[j])) {
  93.                 join(i, j);
  94.             }
  95.         }
  96.     }
  97.     if (fs == -1 || ft == -1) {
  98.         printf("No\n");
  99.     } else {
  100.         printf("%s\n", (find(fs) == find(ft) ? "Yes" : "No"));
  101.     }
  102.  
  103.     return 0;
  104. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement