Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贪心#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; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator