题目大意:

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. [置顶] android 自定义ListView实现动画特效

    通过自定义ListView实现动画特效,被点击元素A向前移,A之前元素往后移动. 重点在于动画的实现: 具体代码如下: package com.open.widget; import java.uti ...

  2. 《Head First 设计模式》学习笔记——工厂模式 + 抽象工厂模式

    设计模式 工厂模式:定义一个创建对象的接口,但由子类决定要实例化的是哪一个.工厂方法让类把实例化推迟到子类. 所谓的"决定",并非指模式同意子类本身在执行时做决定,而是指在编写创建 ...

  3. Qt 学习之路 :线程简介

    现代的程序中,使用线程的概率应该大于进程.特别是在多核时代,随着 CPU 主频的提升,受制于发热量的限制,CPU 散热问题已经进入瓶颈,另辟蹊径地提高程序运行效率就是使用线程,充分利用多核的优势.有关 ...

  4. Reso | The Linux Command Line 的中文版

    http://book.haoduoshipin.com/tlcl/book/zh/ 本书是 The Linux Command Line 的中文版, 为大家提供了多种不同的阅读方式. 中英文双语版- ...

  5. 使用Navicat或PLSQL客户端工具连接远程Oracle数据库(本地无需安装oracle)

    1.首先下载好客户端工具,然后到Oracle官网下载Instant Client: http://www.oracle.com/us/solutions/index-097480.html 解压文件到 ...

  6. java中的数据库事务处理

    /*java使用事务处理,首先要求数据库支持事务,如使用MYSQL的事务功能,就要求mysql的表类型为Innodb,*/ /*InnoDB,是MySQL的数据库引擎之一 与传统的ISAM与MyISA ...

  7. HTML5 离线缓存

    离线资源缓存  为了能够让用户在离线状态下继续访问 Web 应用,开发者需要提供一个 cache manifest 文件.这个文件中列出了所有需要在离线状态下使用的资源,浏览器会把这些资源缓存到本地. ...

  8. windows7在局域网中无法映射驱动器问题解决

    昨天下班时闲的蛋疼,因电脑比较慢,因此在计算机的[系统配置中]的启动选项下对[启动项目]和[服务]做了误操作,导致在计算机重启之后声卡.显卡.网卡等许多服务禁用,更令人费解的是内网中断了连接,无法访问 ...

  9. jrae源码解析(二)

    本文细述上文引出的RAECost和SoftmaxCost两个类. SoftmaxCost 我们已经知道,SoftmaxCost类在给定features和label的情况下(超参数给定),衡量给定权重( ...

  10. Deep Learning学习随记(一)稀疏自编码器

    最近开始看Deep Learning,随手记点,方便以后查看. 主要参考资料是Stanford 教授 Andrew Ng 的 Deep Learning 教程讲义:http://deeplearnin ...