Assume the coasting is a infinite straight line. Land are in one side of coasting, sea in the other. Each small island are a point locating 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 are above 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 a island is represented by its XY coordinates.
Figure A Sample Input of Radar installations
Input
The input consists of several test cases. The "a" 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 installation S needed. "-1" installation means no solution for this case.
Sample Input
3 2
1 2
-3 1
2 1
1 2
1 S
0 0
Sample Output
Case 1:2
Case 2:1
Import java.util.ArrayList;
Import Java.util.Arrays;
Import Java.util.Comparator;
Import Java.util.Scanner;
/** * Created by 95112 on 11/12/2017. */public class Radarinstallation {public static void main (string[] args) {arraylist<string> ANSW
ers = new arraylist<string> ();
int times = 1;
Scanner Scanner = new Scanner (system.in);
int n,d;
do {n = scanner.nextint ();
D = Scanner.nextint ();
if (n==0 && d== 0) break;
island[] Islands = new Island[n];
int maxheigh = 0;
for (int i =0; i < n; i++) {int x, y;
x = Scanner.nextint ();
y = Scanner.nextint ();
if (maxheigh<y) Maxheigh = y;
Double dvalue = math.sqrt (d*d-y *y);
Islands[i] = new Island (x-dvalue,x + dvalue); } if (maxHeigh > D) {answers.add ("case" +times+ ":-1");
times++;
Continue Arrays.sort (Islands, New comparator<island> () {@Override public int c
Ompare (Island O1, Island O2) {if (O1.left < o2.left) return-1;
else return 1;
}
});
int count = 0;
Double end =-999999999999999999999999.0; for (int i =0; i< n; i++) {if (Islands[i].left <= end) {if (islands[i].right
< end] end = Islands[i].right;
}else {count++;
end = Islands[i].right;
} answers.add ("Case" +times+ ":" +count);
times++;
}while (TRUE); For (String aSwer:answers) {System.out.println (answer);
Class island{double left;
Double right;
Public Island (double x,double y) {left = x;
right = y;
}
}