题目:112. 雷达设备
思路:先算出可以覆盖每个小岛的区间l,r,然后按r来排序进行贪心即可
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<double,double>PII;
const int N=1e5+10;
const int mod=100000007;
int n,d;
PII a[1010];
int main(){
cin>>n>>d;
int x,y;
bool flag=1;
for(int i=0;i<n;i++){
cin>>x>>y;
if(y>d) flag=0;
a[i].first=(double)x+sqrt(d*d-y*y);
a[i].second=(double)x-sqrt(d*d-y*y);
}
if(flag){
sort(a,a+n);
double r=-2000;
int ans=0;
for(int i=0;i<n;i++){
if(r<a[i].second){
ans++;
r=a[i].first;
}
}
cout<<ans;
}else{
cout<<-1;
}
return 0;
}