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

G++AC C++WA 代码很短 数论组合排列

Posted by howardcn at 2013-08-16 11:05:58 on Problem 3252
#include <stdio.h>
int C[32][32]={{0}};
void Init()
{
    int i,j;
    C[0][0]=1;
    for(i=1; i<33; i++){
        C[i][0]=1;
        for(j=1; j<=i; j++){
            C[i][j]=C[i-1][j-1]+C[i-1][j];
        }
    }
}

int count(int n)
{
    if(n<=1)return 0;
    int i,j,L=0,zer=0,one=1,res=0;
    bool d[32]={0};
    while(n){
        d[L]=n&1;
        n>>=1,L++;
    }
    for(i=2;i<=L-1;i++)for(j=(i+1)>>1;j<=i-1;j++)
        res+=C[i-1][j];
    for(i=L-1;i>=1;i--){
        if(d[i-1]){
            for(j=i-1;i-1-j+one<=j+zer+1;j--)
                res+=C[i-1][j];
            one++;
        }else{
            zer++;
        }
    }
    return res+(zer>=one);
}

int main()
{
    int s,f;
    Init();
    while(~scanf("%d%d",&s,&f)){
        printf("%d\n",count(f)-count(s-1));
    }
    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