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

看了好久,觉得跟你们写的没差呀,无限WA,大神帮忙看看

Posted by ds570 at 2017-04-19 18:49:03 on Problem 3252
#include<stdio.h>
#include<string.h>
int bit[35];
int c[34][34]={0};

void init()
{
    for(int j=0;j<34;j++)
    {
        for(int i=0;i<=j;i++)
        {
            if(!i||i==j)
                c[i][j]=1;
            else
            {
                c[i][j]=c[i][j-1]+c[i-1][j-1];
            }
        }
    }
}

void tobit(int n)
{
    int cnt=0;
    while(n)
    {
        bit[++cnt]=n%2;
        n/=2;
    }
    bit[0]=cnt;
}

int roudnum(int n)
{
    tobit(n);
    int ans=0;
    for(int i=1;i<bit[0]-1;i++)
    {
        for(int j=i/2+1;j<=i;j++)
        {
            ans+=c[j][i];
        }
    }
    int zero=0;
    for(int i=bit[0]-1;i>=1;i--)
    {
        if(bit[i])
        {
            for(int j=(bit[0]+1)/2-(zero+1);j<i;j++)
            {
                ans+=c[j][i-1];
            }
        }
        else zero++;
    }
    return ans;
}

int main()
{
    int a,b;
    init();
    scanf("%d%d",&a,&b);
    int ans=roudnum(b+1)-roudnum(a);
    printf("%d\n",ans);
    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