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 |
感觉该考虑得都考虑到了……可是为什么不过呢?//2575 Jolly Jumpers #include <iostream> #include <cmath> using namespace std; int main() { int n,num[3001],dif[3000]; int keep; while(cin>>n) { bool isJolly=true; for(int i=1;i<=n;i++) { cin>>num[i]; //if(num[i]>=n || num[i]<=0) isJolly=false; } for(int i=1;i<=n-1;i++) { dif[i]=abs(num[i]-num[i+1]); //cout<<dif[i]<<endl; } keep=dif[2]-dif[1]; for(int i=2;i<=n-2;i++) { if(keep==1) { if((dif[i+1]-dif[i])!=1 || dif[n-1]!=n-1) { isJolly=false; break; } } else if(keep==-1) { if((dif[i+1]-dif[i])!=-1 || dif[1]!=n-1) { isJolly=false; break; } } else { isJolly=false; break; } } if(isJolly) cout<<"Jolly"<<endl; else cout<<"Not jolly"<<endl; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator