Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

改了一下别人的就过了,呵呵,时间还可以(附代码)

Posted by scauben0 at 2005-10-14 14:42:59 on Problem 1844
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator