呢么问题就变成了区间合并问题。给我们n给区间将相交的区间合并求不相交的区间个数。
#include<bits/stdc++.h>
using namespace std;
typedef pair<double,double> pdd;
int n,r,flag;
vector<pdd>ve;
int main(void)
{
cin>>n>>r;
for(int i=0;i<n;i++)
{
double x,y; cin>>x>>y;
if(y>r) flag=1;
double len=sqrt(r*r-y*y);
ve.push_back({
x+len,x-len});
}
double last=-1e9;
int cnt=0;
sort(ve.begin(),ve.end());
for(int i=0;i<ve.size();i++)
if(ve[i].second>last) last=ve[i].first,cnt++;
if(flag) puts("-1");
else cout<<cnt;
return 0;
}