Figure A Sample Input of Radar Installations
Input
The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.
The input is terminated by a line containing pair of zeros
The input is terminated by a line containing pair of zeros
For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.
3 2 1 2 -3 1 2 1 1 2 0 2 0 0
Case 1: 2 Case 2: 1
using namespace std;
typedef struct points{
double x;
double y;}type; bool cmp(type a,type b) {
if (a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main(){
type *pt,*xd;
double x1,x2,border;
int i,j,k,n,count= 1,r,flag= 1,flag1= 0;
while ( scanf( "%d%d",&n,&r))
{
if (n== 0&&r== 0)
break;
pt= new type[n];
xd= new type[n];
for (i= 0;i<n;i++)
{
cin>>pt[i].x>>pt[i].y;
if (pt[i].y>r||r< 0||pt[i].y< 0)
flag1= 1;
}
if (flag1)
{
cout<< "Case"<< " "<<flag<< ":"<< " "<< "-1"<< endl;
flag1= 0;
flag++;
}
else
{
sort (pt,pt+n,cmp);
for (i= 0;i<n;i++)
{
xd[i].x=pt[i].x- sqrt(r*r-pt[i].y*pt[i].y);
xd[i].y=pt[i].x+ sqrt(r*r-pt[i].y*pt[i].y); }border=xd[ 0].y;
for (i= 1;i<n;i++)
{
if (border>xd[i].y)
border=xd[i].y;
else
{
if (xd[i].x>border)
{
border=xd[i].y;
count++;
}
}
}
cout<< "Case"<< " "<<flag<< ":"<< " "<<count<< endl;
count= 1;
flag++;
}
}
return 0;
}