Test instructions: Use radar to cover all islands. Given the number of islands N and the radius of the radar d,n the coordinates of the line (x, y), first the radar interval is calculated and sorted. Then, from left to right, the answer adds 1 when you find that the starting point of the next interval is greater than the minimum end of all the previous intervals.
#include <iostream> #include <algorithm> #include <cmath> using namespace std;
const int maxn=1001;
int ans=0;
int n,d;
BOOL OK;
struct Position {int x;
int y;
}POSITION[MAXN]; BOOL operator < (const Position &a,const Position &b) {return a.x<b.x;} bool operator = = (Const Position &A
Mp;a,const Position &b) {return (a.x==b.x) && (A.Y==B.Y);} void init () {int i;
Ok=true;
for (i=0;i<n;i++) {cin>>position[i].x>>position[i].y;
if (position[i].y>d) {ok=false;
}}} double Getx (Position &position) {return position.x+sqrt (double (D*D-POSITION.Y*POSITION.Y));} void work () {
Double x,temp;
int i;
X=getx (Position[0]);
Ans=1;
for (i=1;i<n;i++) {temp=getx (position[i]);
if (x>temp&&x>position[i].x) {x=temp;
Continue
} if ((position[i].x-x) * (position[i].x-x) + (POSITION[I].Y*POSITION[I].Y) <=d*d) {continue;
} x=getx (Position[i]);
ans++; }} int main (int argc,Char *argv[]) {int casenum=0;
while (Cin>>n>>d &&n!=0&&d!=0) {init ();
casenum++;
if (!ok) {cout<< "case" <<casenum<< ":-1" <<endl;
Continue
} sort (position,position+n);
Work ();
cout<< "Case" <<casenum<< ":" <<ans<<endl;
} return 0; }