标签:
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; struct node { double l,r; //找到以岛为圆心,以d为半径的圆与坐标x轴的左交点l、右交点r //雷达只有设在l~r之间,岛才在雷达覆盖范围内 }a[1005]; int cmp(node a,node b) { return a.l<b.l; } int main() { int n,d; double right; int Cas=0; while(scanf("%d%d",&n,&d)&&n+d) { Cas++; bool flag=1; for(int i=0;i<n;i++) { int x,y; scanf("%d%d",&x,&y); a[i].l=x-sqrt(d*d*1.0-y*y*1.0); a[i].r=x+sqrt(d*d*1.0-y*y*1.0); int dis; if(y<0) dis=-y; else dis=y; if(dis>d) flag=0; } if(!flag) printf("Case %d: -1\n",Cas); else { int ans=1; sort(a,a+n,cmp); right=a[0].r; for(int i=1;i<n;i++) { if(a[i].l>right) { ans++; right=a[i].r; } if(a[i].r<right) right=a[i].r; } printf("Case %d: %d\n",Cas,ans); } } return 0; }
POJ 1328 Radar Installation#贪心(坐标几何题)
标签:
原文地址:http://www.cnblogs.com/atmacmer/p/5223851.html