题目大意:

Round Number:  将一个整数转化为二进制数字后,(不含前导0) 要是0的个数 大于等于1的个数 则是 Round Number

问从L-R之中有多少个Round Number

题目分析:

要转化为2进制数字,我们用10进制保存明显不好判断0和1的个数,所以选择用8进制来存储,这样的话每一次进位会多出 ”000“, 然后再加上8进制的尾数, 最后我们可以得出增加了几个 1 和 增加了 几个 0

需要注意的一点就是, 当前面的数字小于 8 的时候 我们要对 前导 0 进行特殊判断

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef __int64 LL;
LL dp[][][];//dp[位数][0的个数][1的个数]
int bit[];
int binary[][] = { {,}, {,},{,},{,},{,},{,},{,},{,} };
LL dfs(int pos,int preCou0,int preCou1,int flag,int len)
{
if(pos == -)
{
return (preCou1 || preCou0) && preCou0 >= preCou1;//这里要对 0 进行特殊判断, 将0去掉
} if( !flag && dp[pos][preCou0][preCou1] != -)
return dp[pos][preCou0][preCou1]; LL ans = ;
int end = flag?bit[pos]:; for(int i=; i<= end; i++)
{
int nowCou0 = preCou0 + binary[i][];
int nowCou1 = preCou1 + binary[i][];
if(preCou0 == && preCou1 == )//判断是否是第一位,若是第一位则需要进行特殊处理
{
if(i == || i == )nowCou0 = ;
if(i == )nowCou0 = ;
if(i == )nowCou0 = ;
} ans += dfs(pos-, nowCou0, nowCou1, flag && i == end, len);
}
if(!flag)
dp[pos][preCou0][preCou1] = ans; return ans;
} LL solve(LL n)
{
int len = ; while(n)
{
bit[len++] = n%;
n /= ;
} return dfs(len-, , , , len-);
} int main()
{
LL a, b; memset(dp, - ,sizeof(dp));
while(scanf("%I64d%I64d", &a, &b) != EOF)
{
// printf("%I64d\n", solve(a));
// printf("%I64d\n", solve(b));
printf("%I64d\n", solve(b) - solve(a-) );
}
return ;
} /* 0的个数 大于等于 1的个数
1 0001
2 0010 1
3 0011
4 0100 1
5 0101
6 0110
7 0111
8 1000 1
9 1001 1
10 1010 1
11 1011
12 1100 1
13 1101
14 1110
15 1111
16 10000 1 */

POJ 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. 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. POJ3252 Round Numbers —— 数位DP

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

  7. Round Numbers(数位DP)

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

  8. 4-圆数Round Numbers(数位dp)

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

  9. poj3252 Round Numbers (数位dp)

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

随机推荐

  1. strus2与spring3 mvc的差别

    比较了一下strus2与spring3 mvc的差别: spring3 mvc是方法级别的拦截,拦截到方法后根据参数上的注解,把request数据注入进去,在spring3mvc中,一个方法对应一个r ...

  2. 全球最低功耗蓝牙单芯片(DA14580)系统架构和应用开发框架分析

    DA14580是Dialog公司研制的蓝牙单芯片,号称全球功耗最低,是TI CC2541的四分之一,是运动手环等穿戴类电子产品的常用芯片.但是DA14580的开发门槛不低,适合有蓝牙开发经验的团队来开 ...

  3. android 窗体透明的,黑暗度等的设置技巧

    设置透明度(这是窗体本身的透明度,非背景) 1 WindowManager.LayoutParams lp=getWindow().getAttributes(); 2 lp.alpha=0.3f; ...

  4. 边走边学Nodejs (基础入门篇)

    1.什么是Node.js Nodejs ,或者node, 是一个基于ChromeJavaScript执行时建立的平台.用于方便地搭建响应速度快.易于扩展的网络应用.Node.js 使用事件驱动, 非堵 ...

  5. 完美解决Android完全退出程序(转)

    背景:假说有两个Activity, Activity1和Activity2, 1跳转到2,如果要在2退出程序,一般网上比较常见的说法是用 System.exit(0) 或是 android.os.Pr ...

  6. vsftp配置主动模式和被动模式

    配置文件:/etc/vsftpd/vsftpd.conf 主动模式配置方法: 主动式连接使用的数据通道 connect_from_port_20=YES 支持数据流的被动式连接模式 pasv_enab ...

  7. codevs 1213 解的个数(我去年打了个表 - -)

    #include<iostream> #include<cstdio> #include<cstring> using namespace std; int T,x ...

  8. javabean、DTO、VO

    一.javabean 一. javabean 是什么? Bean的中文含义是“豆子”,顾名思义,JavaBean是指一段特殊的Java类, 就是有默然构造方法,只有get,set的方法的java类的对 ...

  9. 自定义鼠标Cursor转变成图片

    今天无意做到项目遇到一个好玩的事情,就是当我鼠标移到一个链接上面,并不是像正常那样出现一个小手,而是变成一个小十字架, 下面看图当时第一眼看到总感觉哪里不对,噢噢噢噢 这样的 小手没了,居然是一个图片 ...

  10. iOS开发之字典数据建立模型步骤

    1. 在控制器属性的(questions)set方法中完成字典转模型的操作 - (NSArray *)questions { if (nil == _questions) { //1.加载plist文 ...