The main idea: there are n points and a value D on the plane, requiring the x-axis of the length of L to select as few points as possible, so that for each given point, there is a selected point from its Euclidean distance of not more than D
Problem solving: Calculate the interval range of each point. The overlapping parts of the interval consist of several intervals, and several points satisfy the requirements.
#include <cstdio>#include <algorithm>#include <cmath>#define MAXN 100010using namespace STD;DoubleL, D;intNstructvillages{DoubleL, R;} VILL[MAXN];BOOLcmpConstVillages A,ConstVillages b) {if(A.R = = B.R)returnA.l < B.L;Else returnA.R < B.R;}intMain () { while(scanf("%LF%LF", &l, &d) = =2) {scanf("%d", &n);DoubleX, y, Len; for(inti =0; I < n; i++) {scanf("%LF%LF", &x, &y); Len =sqrt(D * d-y * y); VILL[I].L = Max (X-len,0.0); VILL[I].R = min (l,x + len); } sort (Vill, Vill + N, CMP);intAns =1;Doubler = vill[0].R; for(inti =1; I < n; i++)if(R >= vill[i].l && r <= VILL[I].R)Continue;Else{ans++; R = VILL[I].R; }printf("%d\n", ans); }return 0;}
UVA-1615 Highway interval Coverage