题意:给了一列点,每个点周围不超过R举例内一定有一个被标记的点,求最少被标记的点的个数。
分析:贪心,从起始位置开始,每次找右边不超过R的最远的位置,然后延伸R的距离,每个点负责的范围就是周围R的距离
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 2010;
int pos[maxn];
int main()
{
int r,n;
while(~scanf("%d%d",&r,&n))
{
if(r == -1 && n == -1)
break;
for(int i = 1; i <= n; i++)
scanf("%d",&pos[i]);
sort(pos + 1,pos + n + 1);
int ans = 0;
int j = 1;
while(j <= n)
{
int st_pos = pos[j++];
while(j <= n && pos[j] - st_pos <= r)j++;
int mark_pos = j - 1;
ans++;
while(j <= n && pos[j] - pos[mark_pos] <= r)j++;
}
cout<<ans<<endl;
}
return 0;
}