1、输入小岛坐标后更新雷达坐标。再将雷达区间按右端点从小到大排序
2、区间选点
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1010;
struct Range
{
double l, r;
bool operator < (const Range& t)
{
return r < t.r; //按右端点升序
}
}range[N];
int n, d;
int main()
{
cin >> n >> d;
bool flag = true;
for (int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
if (y > d) //不会有雷达能检测到
{
flag = false;
break;
}
double l = x - sqrt(d*d - y*y);
double r = x + sqrt(d*d - y*y);
range[i] = {l, r};
}
if (!flag)
{
puts("-1");
return 0;
}
sort(range, range + n);
//枚举每段区间
double maxt = -0x3f3f3f3f, res = 0; //maxt:上一段的右端点
for (int i = 0; i < n; i++)
if (range[i].l > maxt + 1e-9) //若不能有那一段区间有交集,就更新
{
maxt = range[i].r;
res++;
}
cout <<res;
return 0;
}