There are n points on the line, and the position of point I is XI. Select several of these n points and mark them with a tag. For each point, where the distance is within the area of R must have a marked point (its own labeled point, you can think of its distance of 0 points with a marked point), in the case of satisfying this condition, want to be able to add markers for as few points as possible. How many points should be marked at least?
/** * Starting from the far left, it is necessary to have a marked point in the area within which R is located. The point with this marker is on its right. * So this point should be the farthest from the distance within its R. * After locating its mark point, overwrite all points within the distance of R*/#include<stdio.h>intN,r;inta[ +];voidf () {intcn1=0, t=0, i=0; while(i<N) { //find the next starting point while(T>=a[i] && i<n) i++;//find the second starting point after jumping out of the loopt=a[i]+R; //find the next marker point while(T>=a[i] && i<n) i++; Ans++; t=a[i-1]+R; } printf ("%d\n", ans);}intMain () { while(SCANF ("%d%d", &n,&r) = =2){ for(intI=0; i<n;i++) scanf ("%d",&A[i]); f (); } return 0;}
Saruman ' s Army (POJ 3069)