[P3737 HAOI2014] 遥感监测 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
思路:根据圆的性质,将 ( x , y ) (x,y) (x,y)二维平面转为 ( l , r ) (l,r) (l,r)一维线段,进行贪心即可。
代码:
#include <bits/stdc++.h>
using namespace std;
struct no {
double l,r;
bool operator<(const no& rhs) const {
return r < rhs.r;
}
}a[121];
int main()
{
int n,r; cin>>n>>r;
for(int i = 0; i < n; ++i) {
int x,y; cin>>x>>y;
double det = sqrt(r * r - y * y);
a[i] = {x - det, x + det};
}
sort(a, a + n);
int res = 1;
double wz = a[0].r;
for(int i = 1; i < n; ++i) {
if(wz + 1e-6 < a[i].l) {
res++;
wz = a[i].r;
}
}
cout<<res;
}