Advertisement
Dmaxiya

地雷阵 参考代码

Apr 12th, 2025
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const double PI = acos(-1.0);
  6. const int maxn = 100000 + 100;
  7. struct Node {
  8.     double l, r;
  9.     Node() {}
  10.     Node(double l, double r): l(l), r(r) {}
  11. };
  12.  
  13. bool operator<(const Node &a, const Node &b) {
  14.     return a.l < b.l;
  15. }
  16.  
  17. int n;
  18. LL x, y, r;
  19. double k, sum, ll, rr, theta1, theta2;
  20. Node node[maxn];
  21.  
  22. int main() {
  23. #ifdef ExRoc
  24.     freopen("test.txt", "r", stdin);
  25. #endif // ExRoc
  26.     ios::sync_with_stdio(false);
  27.  
  28.     cin >> n;
  29.     for (int i = 0; i < n; ++i) {
  30.         cin >> x >> y >> r;
  31.         double theta = asin(r / sqrt(x * x + y * y));
  32.         double beta = atan(y * 1.0 / x);
  33.         node[i] = Node(beta - theta, beta + theta);
  34.     }
  35.     sort(node, node + n);
  36.     for (int i = 0; i < n; ++i) {
  37.         if (rr < node[i].l) {
  38.             sum += rr - ll;
  39.             rr = node[i].r;
  40.             ll = node[i].l;
  41.         } else {
  42.             rr = max(node[i].r, rr);
  43.         }
  44.     }
  45.     sum += rr - ll;
  46.     printf("%.3lf\n", 1 - sum / (PI / 2));
  47.  
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement