传送门:http://poj.org/problem?id=3069
代码1:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MAXN=1000+5; int a[MAXN]; int solve(int N,int R){ int i=0; int ans=0; while(i<=1000){ while(a[i]==0&&i<=1000){ i++; } if(i>1000) break; if(a[i]+R>=1000){ ans++; break; } i=i+R; while(a[i]==0) i--; ans++; i=i+R+1; } return ans; } int main(){ int N,R; while(cin>>R>>N){ if(R==-1&&N==-1) break; memset(a,0,sizeof(a)); for(int i=0;i<N;i++){ int tmp; cin>>tmp; a[tmp]=1; } cout<<solve(N,R)<<endl; } }
原文:http://www.cnblogs.com/IKnowYou0/p/6358106.html