题目链接:http://poj.org/problem?id=3252

题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers。求区间[L,R]内的 Round Numbers的个数。

思路:

int c[N][N];

void init()
{
    int i,j;
    FOR0(i,N) 
    {
        c[i][0]=c[i][i]=1;
        for(j=1;j<i;j++) c[i][j]=c[i-1][j-1]+c[i-1][j];
    }
}

int n,m;
int b[N],num;

int cal(int n)
{
    if(n<=1) return 0;
    num=0;
    while(n) b[num++]=n&1,n>>=1;
    num--;
    int ans=0,i,j,k;
    for(i=num;i>=1;i--)
    {
        if(i&1)
        {
            k=i/2;
            for(j=k+1;j<=k+k;j++) ans+=c[k+k][j];
        }
        else
        {
            k=i/2;
            for(j=k;j<=k+k-1;j++) ans+=c[k+k-1][j];
        }
    }
    int n0=0,n1=0;
    for(i=0;i<=num;i++)
    {
        if(b[i]) n1++;
        else n0++;
    }
    if(n1<=n0) ans++;
    n0=0; n1=1;
    for(i=num-1;i>=0;i--)
    {
        if(b[i]==0) n0++;
        else
        {
            for(j=i;j>=0&&j+n0+1>=i-j+n1;j--) ans+=c[i][j];
            n1++;
        }
    }
    return ans;
}

int main()
{
    init(); 
    Rush(n)
    {
        RD(m);
        PR(cal(m)-cal(n-1));
    }
}

POJ 3252 Round Numbers(组合)的更多相关文章

  1. [ACM] POJ 3252 Round Numbers (的范围内的二元0数大于或等于1数的数目,组合)

    Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8590   Accepted: 3003 Des ...

  2. POJ 3252 Round Numbers 组合数学

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13381   Accepted: 5208 Description The ...

  3. POJ 3252 Round Numbers

     组合数学...(每做一题都是这么艰难) Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7607 A ...

  4. poj 3252 Round Numbers(数位dp 处理前导零)

    Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...

  5. POJ 3252 Round Numbers 数学题解

    Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...

  6. POJ 3252 Round Numbers(组合数学)

    Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10223   Accepted: 3726 De ...

  7. POJ 3252 Round Numbers(数位dp&amp;记忆化搜索)

    题目链接:[kuangbin带你飞]专题十五 数位DP E - Round Numbers 题意 给定区间.求转化为二进制后当中0比1多或相等的数字的个数. 思路 将数字转化为二进制进行数位dp,由于 ...

  8. POJ - 3252 - Round Numbers(数位DP)

    链接: https://vjudge.net/problem/POJ-3252 题意: The cows, as you know, have no fingers or thumbs and thu ...

  9. poj 3252 Round Numbers 【推导·排列组合】

    以sample为例子 [2,12]区间的RoundNumbers(简称RN)个数:Rn[2,12]=Rn[0,12]-Rn[0,1] 即:Rn[start,finish]=Rn[0,finish]-R ...

随机推荐

  1. Xcode Provisioning 路径

    ~/Library/MobileDevice/Provisioning Profiles

  2. Java7 新特性 switch 可以使用String

    今天和大家分享下 在java7中可以使用String 作为switch 中的参数. 原来在java7之前,switch只能去接收一个 byte.char.short.int 类型 现在在java7中 ...

  3. win下Maven安装和基本设置

    注:本文介绍 Windows 平台上 Maven 的安装.Maven 3 需要运行在 JDK1.4 以上的版本上. 非原创:原创地址 http://www.ibm.com/developerworks ...

  4. [转载]ASP.NET对路径"xxxxx"的访问被拒绝的解决方法小结

    异常详细信息: System.UnauthorizedAccessException: 对路径“D:/temp1/MyTest.txt”的访问被拒绝     在windows 2003下,在运行web ...

  5. [转载]淘宝API调用 申请 获取session key

    http://www.cnblogs.com/zknu/archive/2013/06/14/3135527.html 在调用淘宝的API时,我们都会用到appkey,appsecret,appses ...

  6. 解决eclipse打开报错:failed to create the java virtual ma

    在Eclipse安装目录下找到:eclipse.ini 将如下参数改为: --launcher.XXMaxPermSize 128M ------------------------------- 说 ...

  7. Proxmox虚拟机增加硬盘容量

    1.首先在虚拟机控制台选择调整硬盘容量,弹出窗口为增加的容量 2.重启虚拟机,用fdisk –l查看新增容量是否被识别 3.用cfdisk创建分区,分区格式为Primary 8e (Linux LVM ...

  8. Mongo常用操作

    设置登陆验证 进入Mongo添加用户    db.addUser('root','123456') 编辑Mongo配置文件  vi /etc/mongod.conf   找到#auth = true ...

  9. 漫谈CGI FastCGI WSGI

    作者:auxten链接:https://zhuanlan.zhihu.com/p/20054757来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. CGI(Common ...

  10. Core Java Interview Question Answer

    This is a new series of sharing core Java interview question and answer on Finance domain and mostly ...