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 |
Re:你可以想想更好的算法,这样直接++效率太低了,耗了二三百MS...我懒得想了,靠你了...In Reply To:Re:按你的思路给你改了代码,顺便也借我过了... Posted by:mayp at 2007-03-09 22:13:37 > #include"stdio.h" > #include"math.h" > long int progress(long int n) > { int c,b=0,d=0; > long int m; > m=n; > while(n) > {c=n&1;n>>=1;b+=c;} //将其化为二进制 > while(d!=b) > { > d=0; > m++; > n=m; > while(n) > {c=n&1;n>>=1;d+=c;} //找其与它相邻的二进制 > } > return m; > } > main() > { > long int a; > while(1) > { > scanf("%ld",&a); > if(a==0) break; > printf("%ld\n",progress(a)); > } > } > Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator