给n个区间,设置最少的点,每个区间都有至少一个点
区间按照右端点排序,每次贪心取区间右端点
#include <bits/stdc++.h> using namespace std; const int N=5e4+3; struct T{ double l,r; bool operator<(const T &rh)const{ if(r==rh.r) return l<rh.l; return r<rh.r; } }a[N]; int n,r; void sov(){ int i,ans=0; sort(a+1,a+1+n); double last=-1e9; for(i=1;i<=n;i++){ if(a[i].l>last){ ans++; last=a[i].r; } } cout<<ans; } signed main(){ cin>>n>>r; double x,y; int fg=0; for(int i=1;i<=n;i++){ cin>>x>>y; if(y>r){ fg=1;break;} double t=sqrt(r*r-y*y); a[i].l=x-t,a[i].r=x+t; } if(fg) cout<<"-1"; else sov(); }