题目链接: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. 微软职位内部推荐-Sr SDE for Win Apps Ecosystem

    微软近期Open的职位: Job posting title: Senior Software Design Engineer Location: China, Beijing Level: 63 D ...

  2. 给同一个表中的两个外键写sql

    一个表有两个外键都指向另一个表的主键时,如何检索他们的数据? 例如,表TableA有两个列,puserID和friendID. 表TableB有两个列,userID和userName. 我们怎样检索数 ...

  3. 我的第一个python爬虫程序

    程序用来爬取糗事百科上的图片的,程序设有超时功能,具有异常处理能力 下面直接上源码: #-*-coding:utf-8-*- ''' Created on 2016年10月20日 @author: a ...

  4. Asp.Net原理Version1.0

    Asp.Net原理Version2.0 Asp.Net原理Version3.0_页面声明周期

  5. 本地不安装oracle-client,使用pl/sql developer连接数据库

    一.问题描述 本地未安装oracle-client端,由于机器资源有限,希望通过pl/sql developer进行远程数据库连接.单纯的安装pl/sql developer无法远程连接数据库. 二. ...

  6. iOS开发网络编程之断点续传-NSURLConnection

    最近在做一个小项目的时候,发现使用NSURLSession或者AFNNetworking进行断点续传时诸多的不便,于是自己封装了一个类来实现断点续传,在程序重新启动时仍然可以继续下载(需自己调用方法) ...

  7. uva 11825

    刘书上例题  关于集合的动态规划 #include <cstdio> #include <cstdlib> #include <cmath> #include &l ...

  8. Public, Private and Protect

    public 意味着在其后声明的所有成员对所有的人都可以取. private 意味着除了该类型的创建者和类的内部成员函数之外,任何人都不能存取这些成员. protect 它与private基本相似,只 ...

  9. C# 知识笔记

    HttpContext.Request.Form.ToString() 获取Form表单中的内容 /// <summary> /// 获取 GET 提交方式值 /// </summa ...

  10. JsRender系列demo(4)-if else

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...