POJ3069(贪心)

来源:互联网 发布:三级分销直销系统源码 编辑:程序博客网 时间:2024/05/19 03:23
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int N,R;int x[2100];int main(){#ifdef xxz    freopen("in.txt","r",stdin);#endif // xxz    ios::sync_with_stdio(false);    cin.tie(0);    int sum = 0;    while(cin>>R>>N)    {        if(R == -1 && N == -1) break;        for(int i = 0; i < N; i++) cin >> x[i];        sort(x,x+N);        int j = 0, ans = 0;        while(j < N)        {            int s = x[j++];//s是没有覆盖的最左边的点            while(j < N && s + R >= x[j]) j++;//一直向右前进直到距s的距离大于R的点出现            int f = x[j-1];//f是新加的上标记的点的位置            while(j < N && f + R >= x[j]) j++;//一直向右前进直到找到距f的距离大于R的点            ans++;        }        cout<<ans<<endl;    }    return 0;}

0 0
原创粉丝点击