【POJ3069】Saruman's Army

problem

solution

codes

#include<iostream>
#include<algorithm>
using namespace std;

int N, R, x[1000];

int main(){
    while(cin>>R>>N && R!=-1 && N!=-1){
        for(int i = 0; i < N; i++)cin>>x[i];
        sort(x, x+N);
        int cur = 0, ans = 0;
        while(cur < N){
            int l = x[cur++];
            while(cur<N && x[cur]<=l+R)cur++;
            int r = x[cur-1];
            while(cur<N && x[cur]<=r+R)cur++;
            ans++;
        }
        cout<<ans<<"\n";
    }
    return 0;
}
posted @ 2018-05-26 13:25  gwj1139177410  阅读(71)  评论(0编辑  收藏  举报
选择