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

what's wang with it

Posted by usualy at 2007-08-12 20:44:28 on Problem 1945

#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:
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