本质还是平面积分用散度定理转成线积分,用向量语言写一下。
个圆将平面划分为 个区域,令 ,所求 。
其中 为该区域的面积, 为覆盖该区域的圆的个数。
考虑如何刻画 ,将一个区域看作凸包的每条边上加一个扇形,拆出每条圆弧的贡献。
具体地,设起点 终点 ,圆心 , 在圆上角度分别为 。
贡献 。
化简得到 ,总之好求。
弧个数在 ,每个弧贡献给两个区域,求出圆内部分被覆盖次数 则贡献系数 。
既然和弧所在圆相关,考虑对每个圆逆时针处理上面所有环,将其余圆看作事件插入删除即可。
瓶颈在于圆内对弧排序,复杂度 。
实现中求圆 和圆 两交点在圆 中的角度,比较好的写法是在这个结构上求。
Code
#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;
}