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