Radar installation
Time limit:1000 ms |
|
Memory limit:10000 K |
Total submissions:50740 |
|
Accepted:11394 |
Description
Assume the coasting is an infinite straight line. land is in one side of coasting, sea in the other. each small island is a point locating in the sea side. and any radar installation, locating on the coasting, can only cover D distance, so an island in the sea can be 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 abve X-axis, and the land side below. given the position of each island in 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 an island 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 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
Output
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.
Sample Input
3 21 2-3 12 11 20 20 0
Sample output
Case 1: 2Case 2: 1
Converts a vertex into a range and sorts it by the right endpoint of the range.
The AC code is as follows:
# Include <iostream> # include <cstdio> # include <cmath> # include <algorithm> using namespace STD; struct H {double L, R;} A [1005]; bool CMP (h a, h B) {return. r <B. r ;}int main () {int N, R, BJ; double H, Z; int I, j, CAS = 0; while (CIN> N> r, n! = 0 & R! = 0) {bj = 0; CAS ++; for (I = 0; I <n; I ++) {CIN> H> Z; if (z> r) {bj = 1;} A [I]. L = H-SQRT (R * r-z * z); A [I]. R = H + SQRT (R * r-z * z);} If (bj) {cout <"case" <CAS <": "<-1" <Endl; continue;} Sort (A, A + N, CMP); int ans = 1; double L, R; L = A [0]. l; r = A [0]. r; for (I = 1; I <n; I ++) {if (a [I]. l> r) // It is not difficult to figure out this step {ans ++; r = A [I]. r ;}} cout <"case" <CAS <":" <ans <Endl;} return 0 ;}