POJ 1328 Radar installation (classic greed)

Source: Internet
Author: User
Tags radar

Radar Installation
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 54143 Accepted: 12178

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

Algorithm Analysis:

Just started do not know from which analysis, after pointing to find the center position is a breakthrough. First, the corresponding center position of each point, note if you want to overwrite the most. Each circle tries to make the point exactly at the circle boundary. For example, we have one fruit on each side of the left. We are not sure if we can get two, so that we can get as much as two, we'll just touch one of our left hand. The right hand to grasp another, rather than directly to a certain center and neglect to increase their own can be closer to another opportunity, so the problem becomes the Solution Center. According to the center of the order, constantly update the radar center, finally make the smallest number .

Also, pay attention to the Code Gaze section:

The vertical axis of the center is 0, and the horizontal axis coordinates are calculated:

R=X+SQRT (d*d-y*y)//center shift from left to right

#include <iostream> #include <algorithm> #include <cmath>using namespace std;typedef struct island{ int x;int y;double Z;} Island;island land[1000];int Comp (island A,island b) {return a.z<b.z;} int main () {int N,d,i,count,num=1,sign;while (cin>>n>>d) {sign=0;if (!) ( n| | d) Break;count=1,i=0;while (i<n) {cin>>land[i].x>>land[i].y;land[i].z= (double) land[i].x+sqrt ( Double (d*d-land[i].y*land[i].y));  Center must have floating point number ah have wood if (ABS (LAND[I].Y) >d| | d<=0)                                         //note. When the radar can not be shrouded in the situation output -1sign=1;i++;} if (sign) {cout<< "case" <<num<< ":-1" <<endl;num++;continue;} Sort (land,land+n,comp); Sorts the center position from left to right i=1;double A=land[0].z;while (i<n) {if (! ( (land[i].x-a) * (land[i].x-a) +land[i].y*land[i].y<=d*d)) {a=land[i].z;count++;} i++;} cout<< "Case" <<num<< ":" <<count<<endl;num++;} return 0;}


Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

POJ 1328 Radar installation (classic greed)

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.