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

Description

The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets to be milked first.
They can't even flip a coin because it's so hard to toss using hooves.

They have thus resorted to "round number" matching. The first cow picks an integer less than two billion. The second cow does the same. If the numbers are both "round numbers", the first cow wins,

otherwise the second cow wins.

A positive integer N is said to be a "round number" if the binary representation of N has as many or more zeroes than it has ones. For example, the integer 9, when written in binary form, is 1001. 1001 has two zeroes and two ones; thus,
9 is a round number. The integer 26 is 11010 in binary; since it has two zeroes and three ones, it is not a round number.

Obviously, it takes cows a while to convert numbers to binary, so the winner takes a while to determine. Bessie wants to cheat and thinks she can do that if she knows how many "round numbers" are in a given range.

Help her by writing a program that tells how many round numbers appear in the inclusive range given by the input (1 ≤ Start < Finish ≤ 2,000,000,000).

Input

Line 1: Two space-separated integers, respectively Start and Finish.

Output

Line 1: A single integer that is the count of round numbers in the inclusive range Start..Finish

Sample Input

2 12

Sample Output

6

Source

题意:问在闭区间[n,m]中有多少个数是round numbers。所谓round numbers就是把闭区间中的某一个十进制的数字转换成二进制后0的个数大于等于1的个数,那么这个数就是round
numbers

<pre name="code" class="cpp">#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; int c[33][33] = {0};
int bin[35];
int n,m; void updata() ///计算n个里面取m个的方法数
{
for(int i=0;i<=32;i++)
{
for(int j=0;j<=i;j++)
{
if(j == 0 || i == j)
{
c[i][j] = 1;
}
else
{
c[i][j] = c[i-1][j-1] + c[i-1][j];
}
}
}
} void upbin(int x) /// 将要求的数转化为二进制数而且逆序存储
{
bin[0] = 0;
while(x)
{
bin[++bin[0]] = x%2;
x = x / 2;
}
return ;
} int qurry(int x) ///计算0-n之间的Round Number的个数
{
int sum = 0;
upbin(x);
///求二进制长度小于len的全部二进制数中Round Number的个数
for(int i=1;i<bin[0]-1;i++)
{
for(int j=i/2+1;j<=i;j++)
{
sum += c[i][j];
}
}
int zero = 0;
///求二进制长度等于len的全部二进制数中Round Number的个数
for(int i=bin[0]-1;i>=1;i--)
{
if(bin[i]) ///当前位的值为1
{
for(int j=(bin[0]+1)/2-(zero+1);j<=i-1;j++) ///看懂这里即可了
{
sum += c[i-1][j];
}
}
else
{
zero++;
}
}
return sum;
} int main()
{
updata();
scanf("%d%d",&n,&m);
printf("%d\n",qurry(m+1)-qurry(n));
return 0;
}

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

  1. POJ 3252 Round Numbers 组合数学

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

  2. POJ 3252 Round Numbers(组合)

    题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...

  3. POJ 3252 Round Numbers

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

  4. POJ 3252 Round Numbers 数学题解

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

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

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

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

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

  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. [USACO14FEB]路障Roadblock

    题目:洛谷P2176. 题目大意:有n个点m条无向边,一个人要从1走到n,他会走最短路.现在可以让一条边的长度翻倍,求翻倍后这个人要多走多少距离. 解题思路:首先可以知道,翻倍肯定是在最短路上的某条边 ...

  2. [HNOI2012]矿场搭建(割点)

    [HNOI2012]矿场搭建 题目描述 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出 ...

  3. ArcGIS api for javascript——使用图层定义显示地图

    描述 本例展示如何使用图层定义来限制显示在地图上的图层信息.为了了解本例做了什么,看看用于这个地图的ESRI_Census_USA服务的服务目录页是有帮助的.检查地图中的图层列表.现在注意这行代码限制 ...

  4. No enclosing instance of type E is accessible.

    No enclosing instance of type E  is accessible. 静态方法(main)中调用内部类,会出现这样的问题: 学习了:https://www.cnblogs.c ...

  5. 參加北京bluemix云计算大会偶记

    我就不写散文了.博客也要轻量化. 记录心路历程吧. 这是一次ibm的技术大会.也是传道大会,洗脑大会.会议主题看起来非常多,占领了北京国际饭店的三层,作为一个老ibm bp感受非常多. 1.北京的创业 ...

  6. 减少UIViewController切换的耦合

    我们一般切换UIViewController的时候用的是例如以下代码 #import "UIViewControllerDemo.h" UIViewControllerDemo * ...

  7. 6个技巧加速你的gradle编译

    近期我们都在讨论build系统,我们看了一些技巧能够让你的Maven build更快. 结论和反映都势不可挡.由于我们提供的技巧,很多其它的人都非常高兴能加快他们完毕自己的项目.如今,让我们看一下怎么 ...

  8. 绿色便携版Lazarus的制作教程

    本文来源: www.fpccn.com 原作者:逍遥派掌门人 http://msdn.microsoft.com/zh-cn/library/windows/apps/hh452791.aspx 本教 ...

  9. CentOS 与Ubuntu 安装软件包的对比

    工作需要开始转向centos,简单记录软件包安装 wget不是安装方式 他是一种下载软件类似与迅雷 如果要下载一个软件 我们可以直接 wget 下载地址 ap-get是ubuntu下的一个软件安装方式 ...

  10. 有关R6034错误的思考

    作者:朱金灿 来源:http://blog.csdn.net/clever101 我们有时会遇到R6034错误,工程明明编译通过,但是运行时却出现: 网上的解决办法很多,但是有效的不多,特别是对阐述这 ...