输入样例:
3 2
1 2
-3 1
2 1
输出样例:
2
本题的思路实现求雷达能放的范围,然后对这一区间进行一个排序,然后呢,取最后一个点作为雷达的坐标,因为这样可以覆盖更多的点,如果该点不在下一区间中,这取下一区间的右端点为雷达的坐标。
老师的题解
https://www.acwing.com/solution/content/1061/
图片均转载自yxc老师,yxc老师yyds。讲的很好,建议去学学他的课。
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef pair<double,double> PDD;
const int N=1010;
const double eps=1e-6,Inf=-1e9;
PDD l[N];
int main(void)
{
int n,r,res=0;
bool flag=true;
double last=Inf;
cin>>n>>r;
for(int i=0;i<n;i++)
{
double x,y;
cin>>x>>y;
if(y>r)
flag=false;
double len=sqrt(r*r-y*y);
l[i]={x+len,x-len};
}
sort(l,l+n);
for(int i=0;i<n;i++)
{
if(l[i].second>last+eps)
{
res++;
last=l[i].first;
}
}
if(flag)
cout<<res;
else
cout<<"-1";
}