题目大意:

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. Java并发学习之二——获取和设置线程信息

    本文是学习网络上的文章时的总结,感谢大家无私的分享. Thread类的对象中保存了一些属性信息可以帮助我们辨别每个线程.知道它的一些信息 ID:每一个线程的独特标示: Name:线程的名称: Prio ...

  2. 文字保护纱-Material Design

    Ok,关于这个Material Design 都快被说烂了,他被开发者越来越熟悉的程度,却与市场上的单薄身影形成了鲜明的对比,以至于每当我提及Material Design时就像祥林嫂附身一样. 有些 ...

  3. Android之开发常用颜色

    Android开发中常常要用一些个性化的颜色,然而茫茫的RBG颜色对照表,往往给人眼花缭乱的感觉,更别说从中轻易选出一两种比较满意的颜色,下面我就总结一下开发中常用到的比较绚丽的颜色,都是有名有姓的哦 ...

  4. 动画Rig设置为Legacy

    The animation state AimUp could not be played because it couldn't be found!Please attach an animatio ...

  5. 使用日期工具类:DateUtil

    利用java开发,避免不了String.Date转换,前一天.后一天等问题.给出一个工具类,仅供学习交流. import java.text.DateFormat; import java.text. ...

  6. 登录网站爬虫(保持Cookie不变)

    平时经常需要到学校的信息门户去查看课表及其他信息,于是想做一个爬虫 ,可以自动替我登录并且得到这些信息,于是今天动手写了一个爬虫: 首先登录学校的信息门户:http://cas.whu.edu.cn/ ...

  7. 一道在知乎很火的 Java 题——如何输出 ab【转】

    这是一个源自知乎的话题,原贴链接:一道百度的面试题,有大神会嘛? 虽然我不是大神,但我也点进去看了一下,思考了一会之后有了一些思路,然后去看其它人的答案的时候果然全都已经被各路大神们先想到并贴出来了, ...

  8. JSP学习--常用作用域

    page:当前页面,也就是只要跳到别的页面就失效了 request:一次会话,简单的理解就是一次请求范围内有效 session:浏览器进程,只要当前页面没有被关闭(没有被程序强制清除),不管怎么跳转都 ...

  9. grunt插件[font-spider] : 转码,压缩字体 @font-face

    字蛛插件:压缩与转码静态页面中的 WebFont 需要注意的是,目前只支持 grunt@0.4.1 package.json { "name": "fontS" ...

  10. Hql 执行CRUD

    //新增] @Test public void add(){ config = new Configuration(); sessionfactory = config.configure(" ...