Round Numbers

http://poj.org/problem?id=3252

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 17293   Accepted: 7188

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

 #include<iostream>
#include<cstring>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int dp[][];
int a[];
int num; int dfs(int pos,int sta,bool lead,bool limit){
if(pos==-) return sta>=;
if(!limit&&!lead&&dp[pos][sta]!=-) return dp[pos][sta];
int up=limit?a[pos]:;
int ans=;
for(int i=;i<=up;i++){
if(lead&&i==) ans+=dfs(pos-,sta,lead,limit&&i==a[pos]);
else ans+=dfs(pos-,sta+(i==?:-),lead&&i==,limit&&i==a[pos]);
}
if(!limit&&!lead) dp[pos][sta]=ans;
return ans;
}
int solve(int x){
int pos=;
while(x){
a[pos++]=x%;
x>>=;
}
return dfs(pos-,,true,true);
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n,m;
memset(dp,-,sizeof(dp));
while(cin>>n>>m){
cout<<solve(m)-solve(n-)<<endl;
}
}

Round Numbers(数位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. 4-圆数Round Numbers(数位dp)

    Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14947   Accepted: 6023 De ...

  3. POJ3252 Round Numbers —— 数位DP

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

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

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

  5. poj3252 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(数位DP)

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

  7. poj 3252 Round Numbers 数位dp

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

  8. 【poj3252】 Round Numbers (数位DP+记忆化DFS)

    题目大意:给你一个区间$[l,r]$,求在该区间内有多少整数在二进制下$0$的数量$≥1$的数量.数据范围$1≤l,r≤2*10^{9}$. 第一次用记忆化dfs写数位dp,感觉神清气爽~(原谅我这个 ...

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

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

随机推荐

  1. day01-MySQL介绍

    一.MySQL的介绍 1.1.MySQL介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 W ...

  2. springboot 停止

    因springboot内嵌tomcat或jetty使得我们没法去操作服务: 因此,常常是服务起来后,要重启时会端口占用,我们只能无情的kill掉端口. 不过spring也设置有配置停止的请求: App ...

  3. opencv给图片添加文字水印<转>

    其中有一些改动为了文字大小等还有一些图片的尺寸,真正使用的时候可以把尺寸的屏蔽掉 头文件: //==================================================== ...

  4. confusing c++ 重写 与 重定义 记录1

    class parent { public: void f() { cout << "parent f()" << endl; } void f(int i ...

  5. OS位数,基本概念,结合iOS

    CPU位数,一般指CPU支持的指令集位数,32位CPU对应32位的指令集,64位的CPU对应64位的指令集,不过为了向下兼容,64位CPU也支持32位的指令集. 操作系统位数,一般指操作系统对应的指令 ...

  6. spark sql加载avro

    1.spark sql可以直接加载avro文件,之后再进行一系列的操作,示例: SparkConf sparkConf = new SparkConf().setAppName("Spark ...

  7. 尚硅谷redis学习1-NOSQL简介

    本系列是自己学习尚硅谷redis视频的记录,防止遗忘,供以后用到时快速回忆起来,照抄视频和资料而已,没什么技术含量,仅给自己入门了解,我是对着视频看一遍再写的,视频地址如下:尚硅谷Redis视频 背景 ...

  8. 关于AB包的释放与 Resources.UnloadUnusedAssets的关系

    Resources.UnloadUnusedAssets 并不能释放AB包中东西,只能释放从AB包中加载出来的资源,也可以释放场景中的资源,其它不是从AB包加载来的资源. AB加载后,整个包都加载到内 ...

  9. CocosCreator 自定义TypeScript在VsCode的提示数据

    在assets文件夹外新建xx.d.ts文件如:global.d.ts global.d.ts declare class UserData{ node:cc.Node; name:string; } ...

  10. Kotlin语言编程技巧集

    空语句 Kotlin 语言中的空语句有 {} Unit when (x) { 1 -> ... 2 -> ... else -> {} // else -> Unit } Wh ...