| ||||||||||
| 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 | |||||||||
what's wang with it
#include"stdio.h"
#include"math.h"
#include"string.h"
int b[21000]={0};
int a[110];
int powwer(int n)
{
int i,j,p,s,t,m;
if(b[n]) return b[n];
m=n;
i=0;
while(n>0)
{
a[i]=n%2;
n=n/2;
i++;
}
p=i;
s=0;
for(i=0;i<p;i++)
if(a[i]) s++;
n=pow(2,p)-m;
t=1+powwer(n);
b[m]= s<t?s:t;
return b[m];
}
int main()
{
int n,m,s,t,i,j,p;
while(scanf("%d",&n)!=EOF)
{
i=0;
while(n>0)
{
a[i]=n%2;
n=n/2;
i++;
}
p=i-1;
s=p+powwer(m-pow(2,p));
t=p+1+powwer(pow(2,p+1)-m);
if(s>t) s=t;
printf("%d\n",s);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator