HDU P2089
题目大意为,统计区间内不含4和62的数字的个数;
老实说,看到这题我是抵触的。。。。。
基本上是数位DP的板子,话说数位DP好像全是模板题吧;
预处理,有关的整区间的数字个数;
调用已有的区间,求解0~左端点,0~右端点,然后作差;
具体有关数位DP的事宜
参见:数位DP
代码如下:
#include<cstdio>
#include<cmath>
using namespace std;
int f[][]; int work(int); int main()
{
int n,m,ans=,i,j,k;
f[][]=;
for(k=;k<=;k++)
for(i=;i<=;i++)
if(i!=)
for(j=;j<=;j++)
if(i!=||j!=)
f[k][i]+=f[k-][j];
while(scanf("%d%d",&n,&m)==&&m||n){
ans=work(m);
ans=ans-work(n-);
if(m<n)ans=;
printf("%d\n",ans);
}
} int work(int x)
{
int i,j,k,y=,sum=,z=;
if(x==)return ;
int len=(int)log10(x)+;
int mod=;
for(i=;i<=len-;i++)
mod*=;
for(k=len;k>=;k--){
y=x/mod;
x%=mod;
if(z!=)
for(i=;i<y;i++)
if(z!=||i!=)
sum+=f[k][i];
if(k==&&y!=&&z!=&&(z!=||y!=))
sum++;
if(y==||(z==&&y==))break;
z=y;
mod/=;
}
return sum;
}
祝AC哟;
HDU P2089的更多相关文章
- 「 HDU P2089 」 不要62
和 HDOJ 3555 一样啊,只不过需要多判断个 ‘4’ 我有写 3555 直接去看那篇吧 这里只放代码 #include <iostream> #include <cstring ...
- 有关动态规划(主要是数位DP)的一点讨论
动态规划(dynamic programming)是运筹学的一个分支,是求解决策过程(decision process)最优化的数学方法.20世纪50年代初美国数学家在研究多阶段决策过程的优化问题时, ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- SUSE Linux Enterprise Server设置IP地址、网关、DNS
说明: ip:202.118.83.247 子网掩码:255.255.255.0 网关:202.118.83.2 dns:8.8.8.8 / 8.8.4.4 1.设置ip $ vi /etc/sysc ...
- shell-007:数据库备份,本地保留7天,远程机器保留一个月
## #!/bin/bash d1=`date +%w` # 以周几有变量 d2=`date +%d` # 以每月第几天为变量 local_bakdir=/bak/mysql # 本地备份目录 rem ...
- js字符串去重
js字符串去重: 1. 去掉字符串前后所有空格: function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } ...
- 【算法笔记】A1063 Set Similarity
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be ...
- (转)Centos7上部署openstack ocata配置详解
原文:http://www.cnblogs.com/yaohong/p/7601470.html 随笔-124 文章-2 评论-82 Centos7上部署openstack ocata配置详解 ...
- (转)2017年Linux运维人员必会开源运维工具体系
标签:操作系统 中间件 千里马 Linux 技能 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://oldboy.blog.51ct ...
- DiagnosticFormatter
关于这个类的继承体系如下: 1.DiagnosticFormatter类在com.sun.tools.javac.api包中,其定义如下: /** * Provides simple function ...
- cors允许的方法和contype-type
https://fetch.spec.whatwg.org/#cors-safelisted-request-header get head post text/plain multipart/for ...
- js脚本语言在页面上不执行
转换原理:// 编码原理就是创建TextNode节点,附加到容器中,再取容器的innerHTML.(将脚本编码) // 解码原理是将字符串赋給容器的innerHTML,再取innerText或text ...
- UVM序列篇之二:sequence和item(上)
无论是自驾item,穿过sequencer交通站,通往终点driver,还是坐上sequence的大巴,一路沿途观光,最终跟随导游停靠到风景点driver,在介绍如何驾驶item和sequence,遵 ...