The question is probably like this. It gives you a bunch of numbers. Each number represents a point. It can be understood
Vertices in one-dimensional coordinates, each of which is represented by a number.
We also gave you a number representing the radius.
Give you a rule. When you select a vertex, take it as the center, and the radius can be scanned.
All vertices are marked.
Now you need to mark all vertices and ask you how many times you can mark them.
My practice is greedy. From the leftmost point, count one point. This point just exceeded the leftmost point.
The area that can be scanned as the center, and then centered on this point, then count another point. This point is just
The area that can be scanned by a point that is centered on this page. Select a point that is centered on this page, and so on,
When the last vertex is scanned, the number of marked points is the minimum.
My AC code is as follows:
#include<cstdio>#include<algorithm>using namespace std;int r,num,dot[1010];bool cmp(int a,int b){return a<b;}bool init(){int i;scanf("%d%d",&r,&num);if(r==num&&r==-1)return 0;for(i=0;i<num;i++)scanf("%d",&dot[i]);sort(dot,dot+num,cmp);return 1;}void result(){int i,sum=0,s=0;while(s<num){for(i=s;i<num&&dot[i]<=dot[s]+r;i++);s=i-1;for(i=s;i<num&&dot[i]<=dot[s]+r;i++);s=i;sum++;}printf("%d\n",sum);}int main(){while(init())result();}