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 rangeStart.. Finish

Sample Input

  1. 2 12

Sample Output

  1. 6
  2.  
  3. 题意:给出一个数据范围,求里面的圆数个数有多少,圆数的定义是化为无前导零二进制里面0的个数比1的个数多的话就是圆数
    思路:首先我们范围比较大,我们一个一个判断不太现实,然后它其实就是求给定的二进制位里面0的个数多余1的个数就行,然后我们这个可以进行求一个组合数来解决
  4.  
  5. 分为两部分进行求解
    101010 我会先求出5位的时候,
    那说明第一位是0 第二位是1
    1????
    再从四个位置里面算出0的个数比1的个数多的组合数
    再判断4 3 2 1
  6.  
  7. 第二部分即
    100000-101010范围内
    我们可以从高位开始判断 计算0 1 的数量
    然后0直接忽略
    当判断为1的时候,这时候我可以选择这个位置为0,后面的位置那我就可以随意怎么选求组合数
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<queue>
  5. #include<cmath>
  6. #include<stack>
  7. #include<map>
  8. using namespace std;
  9. int C[][];
  10. int a[];
  11. int suan(int n)
  12. {
  13. int len=;
  14. int k=n;
  15. int sum=;
  16. while(k)
  17. {
  18. a[++len]=k%;
  19. k/=;
  20. }
  21. for(int i=;i<=len-;i++)
  22. {
  23. for(int j=i/+;j<=i;j++)
  24. {
  25. sum+=C[i][j];
  26. }
  27. }
  28. int zero=;
  29. for (int i=len-;i>=;i--)
  30. {
  31. if (a[i])
  32. {
  33. for (int j=(len+)/-(zero+);j<=i-;j++)
  34. {
  35. sum+=C[i - ][j];
  36. }
  37. }
  38. else zero++;
  39. }
  40. return sum;
  41. }
  42. int main()
  43. {
  44. int n,m;
  45. for(int i=;i<=;i++)
  46. {
  47. for(int j=;j<=i;j++)
  48. {
  49. if(i==j||!j) C[i][j]=;
  50. else C[i][j]=C[i-][j-]+C[i-][j];
  51. }
  52. }
  53. scanf("%d%d",&n,&m);
  54. printf("%d\n",suan(m+)-suan(n));
  55. }

POJ - 3252 A - Round Numbers的更多相关文章

  1. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  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. [ACM] POJ 3252 Round Numbers (的范围内的二元0数大于或等于1数的数目,组合)

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

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

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

  6. POJ 3252 Round Numbers 数学题解

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

  7. POJ 3252 Round Numbers 组合数学

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

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

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

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

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

随机推荐

  1. eclipse 快捷键Open Implementation 直接退出

    遇到eclipse 快捷键Open  Implementation 非正常退出.直接关闭的现象. 网查了一下   碰到一篇博客说  和google 输入法有关  卸载了google 输入法就好了 半信 ...

  2. 【Java】【2】String和List相互转换

    正文: 1,String转List //常见的为逗号分隔 String str = "a,b,c"; List<String> list1 = Arrays.asLis ...

  3. arguments.callee用法

    arguments.callee 在哪一个函数中运行,它就代表哪一个函数. 一般用在匿名函数中. 在匿名函数中有时会需要自己调用自己,但是由于是匿名函数,没有名子,无名可调. 这时就可以用argume ...

  4. 成功解决You are using pip version 9.0.1, however version 9.0.3 is available. You should consider upgra

    解决问题 You are using pip version 9.0.3, however version 10.0.1 is available.You should consider upgrad ...

  5. 牛客练习赛32-D-MST+tarjin割边

    链接:https://ac.nowcoder.com/acm/contest/272/D来源:牛客网 题目描述 小p和他的朋友约定好去游乐场游玩,但是他们到了游乐场后却互相找不到对方了. 游乐场可以看 ...

  6. logmnr使用

    logminer 工具的使用 Oracle LogMiner 是Oracle公司从产品8i以后提供的一个实际非常有用的分析工具,使用该工具可以轻松获得Oracle 重作日志文件(归档日志文件)中的具体 ...

  7. Leetcode 117

    if(root == NULL) return; queue<TreeLinkNode *> que; que.push(root); while(!empty(que)){ int le ...

  8. Notes for GGplot2: Getting started with ggplot2

    Alpha-ma 2016/10/7 1 Introduction of GGplot2 ggplot2 is an R package for producing statistical, or d ...

  9. ORACLE PACKAGE中查看包的依赖关系

    SELECT dd.* FROM dba_dependencies dd WHERE NAME <> referenced_name AND referenced_type <> ...

  10. iOS 如何优化项目

    原文 前言 在项目业务趋于稳定的时候,开发完迭代需求后,我们可能会无所适从,进入一段空白期,但是对于攻城狮来说闲暇不是件好事,所以我们可能总想学点什么,却又没有头绪.这个时候我们就可以考虑完善和优化我 ...