POJ 1328Radar Installation

Source: Internet
Author: User
Tags radar

Greedy problem, so-called greedy is just a thought, no specific solution, just to find the most current solution, can more, and finally try to achieve the overall optimal, which is greed.

The problem is that there is an x-axis as the boundary of the coast, above the sea, there is a island, below the land, there is a radar, scanning range is radius d of the circle, can only be installed on the x-axis, the minimum number of installed radar?

, first of all, as long as the point of A and b what is the meaning of the problem can be quickly answered, A and B point to do the center, D for the radius is just the C point, so a to B is a range, in [A, a] to build a circle can be summed up in C (easy), and then the whole problem becomes a , each point of the two left and right points are calculated, according to the left point to sort, and then update the left and right intervals, see Code (L and R), as long as two intervals have a common range, you can use a radar to cover them up;

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5 using namespacestd;6 7 structpoint{8     DoubleLeft ;9     DoubleRight ;Ten}p[1010]; One  A BOOLCMP (Point A, point B) { -     return(A.left <b.left); - } the  - intMain () - { -     intN, D, res, tcase =0; +      while(CIN >> N >> d && (n | |d)) { -         BOOLFlag =false; +          for(inti =0; I < n; i++){ A             Doublex, y; atscanf"%LF%LF", &x, &y); -             if(Y >d) -Flag =true; -             Else{ -P[i].left = X-sqrt (d*d-y*y); -P[i].right = X+sqrt (d*d-y*y); in             } -         } toprintf"Case %d:", ++tcase); +         if(flag) -printf"-1\n"); the         Else{ *Sort (p,p+n,cmp); $res =1;Panax Notoginseng             DoubleL = p[0].left, R = p[0].right; -              for(inti =1; I < n; i++){ the                 if(R <p[i].left) { +res++; AR =P[i].right; the                 } +                 Else if(R >p[i].right) -R =P[i].right; $L =P[i].left; $             } -printf"%d\n", res); -         } the     } -     return 0;Wuyi}
View Code

POJ 1328Radar Installation

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.