Round Numbers
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 6983   Accepted: 2384

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

题意
求二进制表示中0的个数大于1的数的个数。 分析
简单数位DP,用记忆化搜索
#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set> #define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0) using namespace std;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
const int N = 1e6+;
//const int MAXN = 210;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = ;
int T;
void testcase(){
printf("Case #%d: ",++T);
}
const int MAXN = 1e5+;
const int MAXM = ;
int dp[][][];
int bit[];
//num0-0的个数
//num1-1的个数
//limit-边界标志
//z-前缀零标志
int dfs(int pos,int num0,int num1,bool limit,bool z){
if(pos==-) return num0>=num1;
if(!limit&&dp[pos][num0][num1]!=-) return dp[pos][num0][num1];
int ed = limit?bit[pos]:;
int ans=;
for(int i=;i<=ed;i++){
//(z&&i==0)判断是否前面全为零
ans += dfs(pos-,(z&&i==)?:num0+(i==),(z&&i==)?:num1+(i==),limit&&i==ed,z&&i==);
}
if(!limit) dp[pos][num0][num1]=ans;
return ans;
} int solve(int x){
int xx=x;
int tot=;
while(xx){
bit[tot++]=xx&;
xx>>=;
}
return dfs(tot-,,,,);
}
int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL // init();
int l,r;
scdd(l,r);
mset(dp,-);
cout<<solve(r)-solve(l-)<<endl;
return ;
}

 
 

POJ 3252 Round Number(数位DP)的更多相关文章

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

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

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

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

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

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

  4. poj 3252 Round Numbers 数位dp

    题目链接 找一个范围内二进制中0的个数大于等于1的个数的数的数量.基础的数位dp #include<bits/stdc++.h> using namespace std; #define ...

  5. $POJ$3252 $Round\ Numbers$ 数位$dp$

    正解:数位$dp$ 解题报告: 传送门$w$ 沉迷写博客,,,不想做题,,,$QAQ$口胡一时爽一直口胡一直爽$QAQ$ 先港下题目大意嗷$QwQ$大概就说,给定区间$[l,r]$,求区间内满足二进制 ...

  6. 多校5 HDU5787 K-wolf Number 数位DP

    // 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...

  7. POJ Round Numbers(数位DP)

    题目大意: Round Number:  将一个整数转化为二进制数字后,(不含前导0) 要是0的个数 大于等于1的个数 则是 Round Number 问从L-R之中有多少个Round Number ...

  8. POJ3252 Round Numbers —— 数位DP

    题目链接:http://poj.org/problem?id=3252 Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Su ...

  9. Round Numbers(数位DP)

    Round Numbers http://poj.org/problem?id=3252 Time Limit: 2000MS   Memory Limit: 65536K Total Submiss ...

随机推荐

  1. allegro 封装 (引脚编号修改)

    1. 打开dra文件在find里面 off all  然后只点击text 2.点击需要更改的焊盘 3.菜单栏edit - text 4.弹出窗口修改即可

  2. Java内存区域的划分和异常

    Java内存区域的划分和异常   运行时数据区域 JVM在运行Java程序时候会将内存划分为若干个不同的数据区域. 打开百度App,看更多美图 程序计数器 线程私有.可看作是当前线程所执行的字节码的行 ...

  3. Hyperledger Fabric v1.1.0安装记录(国内源版)

    1. 安装虚拟机     虚拟机软件采用:VirtualBox     操作系统选择:Ubuntu 14.04     内存:4G     CPU:2核     硬盘:20G     2.(可选)更改 ...

  4. EOS开发基础之五:使用cleos命令行客户端操作EOS——智能合约之Exchange

    先回答一下上一节中留下的问题,为什么我就看不到eosio这个账户中的钱呢?我明明为它create了很多token啊. 对,你是create了,但是没有issue啊.create了1000000000 ...

  5. [咸恩静][Love effect]

    歌词来源:http://music.163.com/#/song?id=31877654 作曲 : Monster Factory/양승욱 [作曲 : Monster Factory/yang-seu ...

  6. MongoDB 安装教程

    前言: MongoDB是一个基于分布式文件存储的数据库.由C++旨在为WEB应用提供可扩展的高性能数据存储解决方案. 官方网站:https://www.mongodb.com/ 本次教程只针对wind ...

  7. Leetcode题库——36.有效的数独

    @author: ZZQ @software: PyCharm @file: leetcode36_isValidSudoku.py @time: 2018/11/19 19:27 要求:判断一个 9 ...

  8. 接上 操作系统java项目设计图纸 一步一步在进化

  9. java向上转型和向下转型

    转型是在继承的基础上而言的,继承是面向对象语言中,代码复用的一种机制,通过继承,子类可以复用父类的功能,如果父类不能满足当前子类的需求,则子类可以重写父类中的方法来加以扩展. 向上转型:子类引用的对象 ...

  10. ElasticSearch 2 (2) - Setup

    ElasticSearch 2.1.1 (2) - Setup Installation Elasticsearch can be started using: $ bin/elasticsearc ...