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 00448217 at 2005-08-05 17:57:21 on Problem 2453
#include<iostream.h>
#include<math.h>


double qiu(int);

void main()
{
	int i;
	for(;;){
		cin>>i;
		if(i==0) break;
		double k=qiu(i);
		for(int j=i+1;;j++)
			if(k==qiu(j)){
				cout<<j<<endl;
				break;
			}
	}
}

double qiu (int n)
{
	if(n==0) return 0;
	if(pow(2,(int)log(n))==n) return 1;
	
	for(int i=1;;i++)
		if(n>=pow(2,i)&&n<pow(2,i+1))
			return 1+qiu(n-pow(2,i));

}

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