思路
求哪里安装雷达我们可以变为线段交集问题,然后我们考虑怎么样贪心是最优的。
如图,第一个安装雷达的范围我们是必须选的,此时的右端点坐标为(maxx)所有左端点小于这个的我们都可以直接跳过,因为他们有交集。
然后当到达左端点大于他的时候我们需要再贪一个,然后同上,一直更新。
#include <bits/stdc++.h>
#define endl '
'
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(case, x) cout << case << " : " << x << endl
#define open freopen("ii.txt", "r", stdin)
#define close freopen("oo.txt", "w", stdout)
#define IO
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0)
#define pb push_back
using namespace std;
//#define int long long
#define lson rt << 1
#define rson rt << 1 | 1
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> PII;
const int maxn = 2e5 + 105;
struct node{
double l,r;
bool operator<(const node x)const{
return l<x.l;
}
}node[1010];
int main(){
int n,d;
while(~scanf("%d%d",&n,&d)&&n){
bool flag=0;
for(int i=1;i<=n;++i){
double x,y;
scanf("%lf%lf",&x,&y);
if(fabs(y)>d)flag=1;
node[i].l=x-sqrt(d*d-y*y);
node[i].r=x+sqrt(d*d-y*y);
}
if(flag){
printf("-1
");
continue;
}
sort(node+1,node+1+n);
int ans=1;
double maxx=node[1].r;
for(int i=2;i<=n;++i){
if(node[i].l-maxx<1e-7)continue;//node[i].l<=maxx
else ++ans,maxx=max(node[i].r,maxx);
}
printf("%d
",ans);
}
}