POJ 3069 Saruman's Army
贪心,需要被覆盖就找最右可行的盖上
(本蒟一眼看成Salmon's Army……中了AS的毒)
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=1011;
int R, N;
int Num[MAXN];
int r;
int Ans=0;
int main(){
ios_base::sync_with_stdio(false);
while(cin >> R >> N){
if(R<0 || N<=0) break;
Ans=0;
for(int i=1;i<=N;++i) cin >> Num[i];
sort(Num+1, Num+N+1);
r=-R-1;
for(int i=1, j;i<=N;++i){
if(Num[i]-r>R){
/*
for(j=i;j<=N && Num[j]-Num[i]<=R;++j);
r=j;++Ans;
*/
for(j=i;j<N && Num[j+1]-Num[i]<=R;++j);
r=Num[j];++Ans;
//cout << r << " ";
}
}
cout << Ans << endl;
}
return 0;
}