Radar Installation
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 75258 |
|
Accepted: 16841 |
Description assume the coasting is a infinite straight line. Side of coasting, sea in the other. Each of small island was a point locating in the sea side. and any radar installation, locating on the coasting, can only cover D-distance, so a island in the sea can is covered by A RADIUS installation, if the distance between them is at most d.
We Use Cartesian coordinate system, Def Ining The coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of the sea, and Given the distance of the coverage of the radar installation, your task IS-to-write a program-to-find the minimal number of radar installations to cover all the islands. Note that the position of A represented by its X-y coordinates.
Figure A Sample Input of Radar Installations
Input the input consists of several test cases. The first line of all case contains-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 was followed by n lines each containing and 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
Output for each test case output one line consisting of the test case number followed by the minimal number of radar Insta Llations needed. "-1" installation means no solution for this case.
Sample Input
3 2
1 2
-3 1 2
1
1 2
0 2
0 0
Sample Output
Case 1:2 Case
2:1
Source Beijing 2002
The problem is that the ship to the island's range, coincident, no matter, there is no overlap in the addition of a radar.
The solution is inverted, and the method has a record value.
#include <stdio.h> #include <math.h> #include <string.h> #include <algorithm> using namespace
Std
int n,d; struct point {double x, y;}
A[1111]; struct DIS {double s,e;}
B[1111];
BOOL cmp (dis X,dis y) {return x.e<y.e;} double com1 (double x,double y) {double sum=sqrt (1.0*d*d-y*y);
return x-sum;
} double com2 (double x,double y) {double sum=sqrt (1.0*d*d-y*y);
return x+sum;
} int main () {double s,e,temp;
int i,count=1; while (scanf ("%d%d", &n,&d), n| |
d) {int flag=0;
for (i=0;i<n;i++) {scanf ("%lf%lf", &a[i].x,&a[i].y);
if (a[i].y>d) {flag=1;
Continue } s=com1 (A[I].X,A[I].Y);
E=com2 (A[I].X,A[I].Y);
if (s>e) {temp=s;
S=e;
E=temp;
} b[i].s=s;
b[i].e=e;
} if (flag) printf ("Case%d: -1\n", count++);
else {sort (b,b+n,cmp);
Double max=b[0].e;
int Ans=1;
for (i=1;i<n;i++) {if (MAX>=B[I].S) continue;
MAX=B[I].E;
ans++; } printf ("CASE%d:%d\n ", Count++,ans);
}} return 0; }