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"stdio.h" #include"math.h" int flag=1; int fun(int p) { unsigned int i,m,n,inv,temp; temp=p; //printf("p=%d,",p); for(i=0,m=0,n=0;i<16;i++) {if(1==p%2){m++;n=i;}p=p>>1;} //printf("m=%u,n=%u,",m,n); if(m==1 && flag==1){return n;} if(flag==1){flag++;} if(m==1 && flag!=1)return 1; inv=fun((int)pow(2,n+1)-temp); //printf("inv=%d\n",inv); if(m-1>1+inv) {return n+inv+1;} else {return n+m-1;} } main() { int p; while(scanf("%d",&p)!=EOF) { printf("%d\n",fun(p)); flag=1; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator