Original question:
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 Be covered by a RADIUS installation, if the distance between them are 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.
Input
The input consists of several test cases. The first line of each case contains integers n (1n) 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 nlines each containing and integers representing the coordinate of the position of EAC H 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 the case.
Sample Input
3 21 2-3 12 11 20 20 0
Sample Output
Case 1:2case 2:1
Test instructions
Given an axis, the positive half axis of y is the sea, the negative half axis is the continent, the X axis is the coastline;
Then there are many islands on the sea that require radar surveillance, and now the question is, how many radars are needed to cover all these islands at least?
Analysis: Can be resolved into the region to select the least point problem, pay attention to replace OK
Code:
#include <iostream>#include<iomanip>#include<cstdio>#include<cmath>#include<algorithm>#include<cstring>using namespacestd;structnode{Doublex, y; BOOL operator< (node &b)Const { returnY<b.y | | (y = = b.y&&x>b.x); }}point[ ++Ten];intMain () {intN, D; Doublex, y; intKase =0; while(CIN >> n >> d&&n! =0&& d! =0) {Kase++; intOK =1; intCNT =0; for(inti =0; I < n; i++) {scanf ("%LF%LF", &x, &y); if(y>d) {OK=0; } Else{point[i].x= X-sqrt (d*d-y*y); Point[i].y= x + sqrt (d*d-y*y); }} getchar (); Sort (point, Point+N); Doubleend; for(inti =0; I < n; i++) { if(i = =0) {End=point[i].y; Continue; } if(End <point[i].x) {End=point[i].y; CNT++; } } if(OK = =0) {printf ("Case %d: -1\n", Kase); } Else{printf ("Case %d:%d\n", Kase, CNT +1); } } return 0;}
UVALive-2519 Radar installation problem solving experience