Radar installation (greedy, can be converted to this summer holiday not AC type)

Source: Internet
Author: User
Tags radar

Radar installationtime limit:2000/1000ms (java/other) Memory limit:20000/10000k (Java/other) total submission (s): 54 Accepted Submission (s): 28Problem 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 2 1 2-3 1 2 1 1 2 0 2 0 0

Sample outputcase 1:2 Case 2:1: First conversion to interval points, then sorting, the interval to find points; code:
1#include <stdio.h>2#include <math.h>3#include <algorithm>4 using namespacestd;5 structnode{6     Doubles,e;7 };8 intn,d,k;9Node area[1010];Ten intCMP (Node A,node b) { One     returna.e<B.E; A } - intChangeintXinty) { -     if(y>d)return 0; the     DoubleA,B,M=SQRT (d*d-y*y); -a=x-m;b=x+m; -area[k].s=a;area[k].e=b;k++; -     return 1; + } - intMain () {intT,x,y,flot,temp,num,l=0; +      while(SCANF ("%d%d", &n,&d), n| | d) {k=0; flot=1; temp=0; num=1; l++; A              for(intI=0; i<n;i++){ atscanf"%d%d",&x,&y); -t=Change (x, y); -                 if(!t) flot=0; -             } -Sort (area,area+k,cmp); -              for(intI=0; i<k;i++){ in                 if(AREA[I].S&GT;AREA[TEMP].E) temp=i,num++; -             } toprintf"Case %d:%d\n", l,num); +     } -     return 0; the}

Radar installation (greedy, can be converted to this summer holiday not AC type)

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.