(~ ̄▽ ̄) ~*
#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespacestd;structnode{DoubleL,r; //Find the circle centered on the island with the radius of D and the left intersection of the x-axis, L, right intersection R//Radar is only located between L~r and the island is within radar coverage.}a[1005];intCMP (node A,node b) {returna.l<B.L;}intMain () {intn,d; DoubleRight ; intcas=0; while(SCANF ("%d%d", &n,&d) &&n+d) {Cas++; BOOLflag=1; for(intI=0; i<n;i++) { intx, 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); intdis; if(y<0) dis=-y; Elsedis=y; if(dis>d) flag=0; } if(!flag) printf ("Case %d: -1\n", Cas); Else { intans=1; Sort (A,a+n,cmp); Right=a[0].R; for(intI=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# greedy (coordinate geometry problem)