Radar installationtime limit:2000/1000ms (java/other) Memory limit:20000/10000k (Java/other) total submission (s): 22 Accepted Submission (s): 9Problem Descriptionassume 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
Inputthe 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
Outputfor each test case output one line consisting of the "test case" number followed by the minimal number of radar instal Lations needed. "-1" installation means no solution for this case.
Sample INPUT3 21 2-3 12 1 1 20 2 0 0
Sample outputcase 1:2case 2:1 Solutions: First calculate the area can cover the island, and then the interval according to the right side of the interval from small to large, to find out if there is a repetition interval
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h>using namespace STD; #define MAX 11000struct node{double beg;double end;} S[max];bool CMP (node A,node b) {return a.beg<b.end;} int main () {int i,j;int island,r;double a,b;int k=0; while (scanf ("%d%d", &island,&r) &&island!=0&&r!=0) { int ok=0; for (i=0;i<island;i++) { scanf ("%lf%lf", &a,&b); if (Fabs (b) >r) { ok=1; break; } S[I].BEG=A-SQRT (R*R-B*B)///Interval left s[i].end=a+sqrt (r*r-b*b);//Interval right-side } if (OK) { printf ("-1 \ n "); Continue; } Sort (s,s+island,cmp); int sum=0; Double ans=-11000.0; for (i=0;i<island;i++) { if (Ans<s[i].beg) { ans=s[i].end; sum++; } } printf ("Case%d:", ++k); printf ("%d\n", sum); } return 0;}
POJ 1328 Radar Installation "greedy interval points"