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.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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator