P6376 [PA 2010] The Goat

· · 题解

本质还是平面积分用散度定理转成线积分,用向量语言写一下。

其中 $S_i$ 为该区域的面积,$c_i$ 为覆盖该区域的圆的个数。 考虑如何刻画 $S$,将一个区域看作凸包的每条边上加一个扇形去掉三角形的部分,拆出每条圆弧的贡献。 >具体地,设起点 $A$ 终点 $B$,圆心 $(x_0,y_0)$,$A,B$ 在圆上角度分别为 $\alpha,\beta$。 > >贡献 $(x_0+r\cos\alpha,y_0+r\sin\alpha)\times (x_0+r\cos \beta,y_0+r\sin\beta)+\frac{1}{2}(\beta-\alpha)r^2-\frac{1}{2}r^2\sin(\beta-\alpha)$。 > >化简得到 $\frac{r}{2}(x_0\sin\beta+y_0\cos\alpha-y_0\cos\beta-x_0\sin\alpha+r(\beta-\alpha))$,总之好求。 弧个数在 $\mathcal O(n^2)$,每个弧贡献给两个区域,求出圆内部分被覆盖次数 $x$ 则贡献系数 $P(x+1)-P(x)$。 既然和弧所在圆相关,考虑对每个圆逆时针处理上面所有环,将其余圆看作事件插入删除即可。 瓶颈在于圆内对弧排序,复杂度 $\mathcal O(n^2\log n)$。 实现中求圆 $j$ 和圆 $i$ 两交点在圆 $i$ 中的角度,比较好的写法是在这个结构上求。 ![](https://cdn.luogu.com.cn/upload/image_hosting/7e16a6bg.png?x-oss-process=image/resize,m_lfit,h_340,w_550) ::::info[Code] ```cpp #include <bits/stdc++.h> using namespace std; #define IL inline const int N = 1005; const double pi = acos(-1); struct Point { double x, y; } a[N]; struct Event { double a; int flg; }; IL bool operator<(Event a, Event b) { return a.a < b.a; } int n, k; double r, ans, P[N]; IL double cal(double x, double y, double a, double b) { return r / 2 * (x * (sin(b) - sin(a)) + y * (cos(a) - cos(b)) + r * (b - a)); } signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> r; for (int i = 1; i <= n; ++i) cin >> a[i].x >> a[i].y; for (int i = 1; i <= n; ++i) P[i] = 1 - pow(1 - 1.0 * i / n, k); for (int i = 1; i <= n; ++i) { vector<Event> e; int cnt = 0; for (int j = 1; j <= n; ++j) { double x = a[j].x - a[i].x, y = a[j].y - a[i].y; double d = sqrt(x * x + y * y); if (j == i || d >= 2 * r) continue; double a0 = atan2(y, x), al = acos(d / 2 / r); double a = a0 - al, b = a0 + al; if (a <= -pi) a += 2 * pi; if (b >= pi) b -= 2 * pi; cnt += a > b, e.push_back({a, 1}), e.push_back({b, -1}); } e.push_back({pi, 0}); sort(e.begin(), e.end()); double lst = -pi; for (auto [now, c] : e) { if (now != lst) ans += (P[cnt + 1] - P[cnt]) * cal(a[i].x, a[i].y, lst, now); lst = now, cnt += c; } } cout << fixed << setprecision(10) << ans << '\n'; return 0; } ``` ::::