poj1328 greedy radar, land, island issues

Source: Internet
Author: User
Tags radar

Radar Installation
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 60381 Accepted: 13610

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 2002Test Instructions: There is an axis on the x axis above the sea is the land x-axis is the coastline, the Sea has n small islands, now to install radar on the coastline,

Radar coverage is a circle with a radius of R, please cover all the islets with a minimum of radar; output-1 when unable to overwrite

Idea: Calculate the center of the radar where each island can be covered, that is, a circle with the radius of the small island as the center of R, the intersection of the circle and the x-axis:

The left intersection is X-SQRT (r*r-y*y); The right intersection is X+SQRT (r*r-y*y);

Sort by the left node, if the left intersection of I points is on the right side of the current radar, a new radar will be installed to update the radar

Otherwise, if the right intersection point of I is also on the left side of the current radar, the center of the current radar is updated to the right intersection point;

Code

::

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace Std;
struct node{
Double X;
Double y;
}QUE[1005];
BOOL CMP (struct node a,struct node B) {
Return a.x<b.x;
}
int main () {
int n;
Double D;
int count=0;
while (scanf ("%d%lf", &n,&d)!=eof) {
int sum;
if (n==0&&d==0)
Break
int flag=0;
count++;
for (int i=0;i<n;i++) {
Double A, B;
scanf ("%lf%lf", &a,&b);
QUE[I].X=A-SQRT (D*D-B*B);
QUE[I].Y=A+SQRT (D*D-B*B);
if (b>d| | d<=0| | B&LT;0)
flag=1;

}
if (!flag) {
Sort (que,que+n,cmp);
Double temp;
TEMP=QUE[0].Y;
Sum=1;
for (int i=1;i<n;i++) {
if (que[i].x>temp) {
sum++;
TEMP=QUE[I].Y;
}
else if (que[i].y<temp) {
TEMP=QUE[I].Y;
}
}
}
if (flag)
printf ("Case%d: -1\n", count);
Else
printf ("Case%d:%d\n", count,sum);
}
return 0;
}

poj1328 greedy radar, land, island issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.