poj1328 Radar Installation Range greedy

Source: Internet
Author: User

Main topic:

Select as few points as possible on the X axis as the center of the circle with a radius of D. So that these circles can cover all the points.

Ideas:

Convert each point to the x-axis. That is, the range of positions that can cover the center of the point [A, b]. Then follow each point corresponding to a from small to large sort. The 1th requires special treatment, and we assign a value of r=b0. That is to make the center of the first circle the horizontal axis as large as possible. Then traverse the remaining points. For the I point, if the AI of the point is greater than r, you need to add a circle with the center of BI; Otherwise, update R to the value of R and bi small.

Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 8 Const intN =1010;9 structnodeTen { One     Doublex, y; A     Doubleb; - }p[n]; - BOOLCMP (node n1,node n2) the { -     returnn1.a<n2.a; - } - intMain () + { -     //freopen ("Test.txt", "R", stdin); +     intN,d,ca=1; A      while(SCANF ("%d%d", &n,&d)!=eof&&N) at     { -         inti; -         BOOLflag=0; -          for(i=0; i<n;i++) -         { -scanf"%LF%LF",&p[i].x,&p[i].y); in             if(p[i].y>d) flag=1; -         } toprintf"Case %d:", ca++); +         if(flag) printf ("-1\n"); -         Else the         { *              for(i=0; i<n;i++) $             {Panax Notoginseng                 Doublex=p[i].x,y=p[i].y; -P[I].A=-SQRT (d*d-y*y) +x; theP[I].B=SQRT (d*d-y*y) +x; +             } ASort (p,p+n,cmp); the             Doubler=p[0].b; +             intans=1; -              for(i=1; i<n;i++) $             { $                 if(p[i].a>R) { -R=p[i].b; -ans++; the                 } -                 if(P[i].b<r) r=p[i].b;Wuyi             } theprintf"%d\n", ans); -         } Wu     } -     return 0; About}
View Code

poj1328 Radar Installation Range 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.