POJ 1328 Radar Installation
事实上,一个点被一个圆覆盖可以转化成区间问题。
#include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm> using namespace std; const int maxn=1000+10; struct X { double x,y; double L,R; } s[maxn]; double d; int n; bool fail; bool cmp(const X&a,const X&b) { if(a.L==b.L) return a.R<b.R; return a.L<b.L; } int main() { int T=1; while(~scanf("%d%lf",&n,&d)) { if(n==0&&d==0) break; fail=0; for(int i=1; i<=n; i++) scanf("%lf%lf",&s[i].x,&s[i].y); for(int i=1; i<=n; i++) { if(s[i].y>d) fail=1; s[i].L=s[i].x-sqrt(d*d-s[i].y*s[i].y); s[i].R=s[i].x+sqrt(d*d-s[i].y*s[i].y); } sort(s+1,s+1+n,cmp); int ans=0; double st=-123456789,en=-123456789; for(int i=1; i<=n; i++) { if(s[i].L>=st&&s[i].L<=en) { st=max(st,s[i].L); en=min(en,s[i].R); } else { ans++; st=s[i].L; en=s[i].R; } } printf("Case %d: ",T++); if(fail) printf("-1\n"); else printf("%d\n",ans); } return 0; }