ACM Radar Placement Problem

Source: Internet
Author: User
Tags radar

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<tex2html_verbatim_mark> distance , so an island in the sea can be covered by a RADIUS installation, if the distance between them are at most D& Lt;tex2html_verbatim_mark>.

We use Cartesian coordinate system, defining the coasting is the x<tex2html_verbatim_mark>-axis. The sea side is above x<tex2html_verbatim_mark>-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 represented by its x<tex2html_verbatim_mark> y< ; tex2html_verbatim_mark>coordinates.

<tex2html_verbatim_mark>

Input

The input consists of several test cases. The first line of all case contains integers n<tex2html_verbatim_mark>(1n) < Tex2html_verbatim_mark> and D<tex2html_verbatim_mark>, where n<tex2html_ Verbatim_mark> is the number of islands in the sea and D<tex2html_verbatim_mark> is the distance of Coverage of the radar installation. This was followed by n<tex2html_verbatim_mark> lines each containing and integers representing the CO Ordinate 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 the case.

Sample Input

3 21 2-3 12 11 20 20 0

Sample Output

Case 1:2case 2:1

Problem Solving Ideas:

The main idea of this topic is that there is an axis above the x-axis is the land on the 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. We can figure out the center of the radar where each island can be covered, that is, a circle with a radius of R for the small island, 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), and according to the left intersection, if the left intersection of I points is on the right side of the current radar, a new radar should 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 of the point.

Program code:

#include <iostream> #include <algorithm> #include <cmath>using namespace std;const int N = 1001;struct Node{double L,r;} A[n];bool Fun (Node A, Node B) {return A.L<B.L;} int main () {int n,r,i,case=0;double x,y,t;while (scanf ("%d%d", &n, &r) &&n&&r) {int v=1;for (i=0; i<n; i++) {cin>>x>>y;a[i].l = X-sqrt (r*r-y*y); A[I].R = x + sqrt (r*r-y*y); if (Y>r | | r<=0 | | y<0) V=-1;} Sort (A, a+n,fun); t = a[0].r;for (i=1; i<n && v!=-1; i++) if (a[i].l>t) {v++;t = A[I].R;} else if (a[i].r<t) t=a[i].r;printf ("Case%d:%d\n", ++case, V);} return 0;}     

  

ACM Radar Placement Problem

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.