Radar Installation
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 64121 |
|
Accepted: 14418 |
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, defining 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 is 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 all test case output one line consisting of the test case number followed by the minimal number of radar installation S needed. "-1" installation means no solution for this case.
Sample Input
3 21 2-3 12 11 20 20 0
Sample Output
Case 1:2case 2:1
Source
Beijing 2002 Interval Point (conversion idea):
<1>: The left endpoint is sorted (small → large), the left endpoint is the same, (small → large) The right end of the row;
<2>: For Num[0], on the right end of the radar, if the next interval left endpoint > now right endpoint, radar shu+1, if the left endpoint < right end point: If the next interval right endpoint < Now right endpoint, update the radar to the next interval right end;
1#include <cmath>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 6 struct Island7 {8 DoubleL, R;9} num[1010];Ten One BOOLCMP (Island L, Island R) A { - if(L.L = =R.L) - returnL.R <R.R; the returnL.L <R.L; - } - - intMain () + { - DoubleR, X, y;intI, M, t=1; + while(~SCANF ("%d%lf", &m, &R)) A { at intFlag =0; - if(M = =0&& r = =0) - Break; - for(i=0; i<m; i++) - { -scanf"%LF%LF", &x, &y); in if(Y >R) -{flag =1;Continue; } toNUM[I].L = X-sqrt (r*r-y*y);//conversion to interval problem; +NUM[I].R = x + sqrt (r*r-y*y); - } the if(flag) * { $printf"Case %d: -1\n", t++); Panax Notoginseng Continue; - } theSort (num, num+m, CMP); + Doubletemp = num[0].R;intTotal =1; A for(i=1; i<m; i++) the { + if(Num[i].l >temp) { -total++; $temp =NUM[I].R; $ } - - if(Num[i].l <=temp) the { - if(NUM[I].R <temp)Wuyitemp =NUM[I].R; the } - } Wuprintf"Case %d:%d\n", t++, total); - } About return 0; $}
Poj1328--radar installation (range selected)