poj1328 Radar Set Greedy

Source: Internet
Author: User
Tags radar

Radar Installation

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
This topic is similar to the following topic
"Greedy" radar problem
Title DescriptionZhang Qiman and other people use space-time radar to locate Li Xulin location. 7.3, the space-time radar in a straight line, above the line is the space of the sea, each person in the space of the sea is like an island in the sea, the location of these people are known, each radar scan range is a radius d of the circular area, asked at least how many radars to cover all the people (islands).

Inputthe input includes multiple sets of test data, the first behavior of each set of test data is two integers n (1≤n≤1000) and D, that is, the number of islands and the radar scan radius. The next n rows are two integers per line representing the island coordinates. Each set of test data is separated by a blank line interval, and all test data ends with 0 0. Outputthe output requires a minimum number of radars to be installed, one row per group. If no solution is represented by-1. I want to use the point as the origin, r is the radius of the x-axis and the left end of the order, sweep it all over again, but suddenly think of a situation, will make the left endpoint satisfies the situation, but the right endpoint is not satisfied. So to update the right endpoint.
#include <iostream>#include<algorithm>#include<cmath>#include<cstdio>using namespacestd;Const intMAXN =1005;structUCT {DoubleLeft , right;};BOOLCMP (UCT A, uct b) {returnA.left <B.left;}intMain () {Ios::sync_with_stdio (false);    UCT S[MAXN]; intK =0, N, R;  while(Cin >> N >>R) {intFlag =1; if(n = =0&& R = =0) Break;  for(inti =0; I < n; i++){            intx, y; CIN>> x >>y; if(ABS (Y) <=R) {                DoubleLen = sqrt ((r*r-y*y) *1.0); S[i].left= X-Len; S[i].right= x +Len; }ElseFlag =0; //cout << i << "<<x <<" "<<y << Endl;        }        if(flag) {sort (s, S+N, CMP); intCNT =1; DoubleEnds = s[0].right;  for(inti =0; I < n; i++){                if(S[i].left >ends) {Ends=S[i].right; CNT++; }Else if(S[i].right <ends) {Ends=S[i].right; }} cout<<" Case"<< ++k <<": "<< CNT <<Endl; }  Elsecout<<" Case"<< ++k <<": "<<-1<<Endl; }    return 0;}
It's been lazy lately.

poj1328 Radar Set Greedy

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.