D. Capture Stars
反演
定义
若 (OPcdot OP' = r^2) , 则称 (P) 与 (P') 关于 (O) 互为反演,反演半径为 (r)
该题反演后,转化为很简单的问题
#include<bits/stdc++.h>
using namespace std;
int T, n, R, r, cnt;
const int N = 1e4 + 10;
double x[N], y[N];
const double eps = 1e-8;
struct node {
double y;
int val;
bool operator < (const node& b)const {
return fabs(y - b.y) < eps ? val > b.val : y < b.y;
}
}A[N<<1];
void insert(int idx) {
double d = fabs(1.0 * R * R / r + R - x[idx]);
double dy = sqrt((1.0 * R * R / r - R) * (1.0 * R * R / r - R) - d * d);
A[cnt++] = { y[idx] + dy ,-1 };
A[cnt++] = { y[idx] - dy,1 };
}
int main() {
scanf("%d", &T);
while (T--) {
cnt = 0;
scanf("%d%d%d", &n, &R, &r);
for (int i = 0; i < n; i++) {
scanf("%lf%lf", x + i, y + i);
double dis = sqrt(x[i] * x[i] + y[i] * y[i]);
double t = 4 * R * R / (dis*dis);
x[i] *= t; y[i] *= t;
insert(i);
}
//x = R*R/r + R
int ans = 0, now = 0;
sort(A, A + cnt);
for (int i = 0; i < cnt; i++) {
now += A[i].val;
ans = max(ans, now);
}
printf("%d
", ans);
}
}