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> using namespace std; int main(){ unsigned long N; while(cin>>N) { unsigned long sum=0; unsigned long i; for(i=1;;i++){ sum+=i; if(sum>N) break; } unsigned int n; if(sum%2==1&&N%2==0) {i++;sum+=i;} if(sum%2==0&&N%2==1) {i++;sum+=i;} if(sum==N) { n=i; } else{ unsigned long x=sum-N; if(x%2==0) { n=i; } else { n=i+1; } if(x==1){ n=i+1; } } if(N==1) cout<<"1"<<endl; if(N==3) cout<<"2"<<endl; if(N!=3&&N!=1) cout<<n<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator