杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。

杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。

不吉利的数字为所有含有4或62的号码。例如:

62315 73418 88914

都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。

你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。

Input

输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。

Output

对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。

Sample Input

1 100

0 0

Sample Output

80

要不出现4和62,数位dp,两种方法,一种是先用数组存每个位数上的数字的时候有多少答案,另一种是数位dp的模板写法,临时求,不过可以用dp数组存已经找过的

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define sca(x) scanf("%d",&x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1000005;
int dp[15][15];
int num[15];
void first()
{
mm(dp,0);dp[0][0]=1;
rep(i,1,10)
rep(j,0,10)
{
if(j==4)
continue;
else
rep(k,0,10)
{
if(j==6&&k==2)
continue ;
dp[i][j]+=dp[i-1][k];
}
}
}
int solve(int x)
{
int n=x,cnt=1,ans=0;
while(n>0)
{
num[cnt++]=n%10;
n/=10;
}
num[cnt]=0;
per(i,cnt-1,1)
{
rep(j,0,num[i])
{
if(j==4||(j==2&&num[i+1]==6))
continue;
ans+=dp[i][j];
}
if(num[i]==4||(num[i]==2&&num[i+1]==6))
break;
}
return ans;
} int main()
{
first();
int l,r;
while(cin >> l >>r &&(l||r))
{
cout<<solve(r+1)-solve(l)<<endl;
}
return 0;
}

数位dp模板写法

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define sca(x) scanf("%d",&x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1000005;
int dp[15][2];
int num[15];
int dfs(int pos,int if6,int limit)
{
int ans=0;
if(!pos) return 1;
int up=limit?num[pos]:9;
if(!limit&&dp[pos][if6]!=-1) return dp[pos][if6];
rep(i,0,up+1)
{
if(i==4) continue;
if(i==2&&if6) continue;
ans+=dfs(pos-1,i==6,limit&&i==up);
}
if(!limit) dp[pos][if6]=ans;
return ans;
}
int solve(int x)
{
mm(num,0);
int pos=0;
while(x)
{
num[++pos]=x%10;
x/=10;
}
return dfs(pos,0,1);
}
int main()
{
mm(dp,-1);
int l,r;
while(cin >> l >>r &&(l||r))
{
cout<<solve(r)-solve(l-1)<<endl;
}
return 0;
}

A - 不要62的更多相关文章

  1. VS2015编译boost1.62

    VS2015编译boost1.62 Boost库是一个可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一. Boost库由C++标准委员会库工作组成员发起,其中有些内容有 ...

  2. P87LPC760/61/62/64/67/68/69/78/79芯片解密单片机破解价格

    NXP恩智浦P87LPC760/61/62/64/67/68/69/78/79芯片解密单片机破解 NXP LPC700系列单片机解密型号: P87LPC759.P87LPC760.P87LPC761. ...

  3. HDU2089 不要62[数位DP]

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. Connection broken for id 62, my id = 70, error =

    启动费zokeeper失败,报错如下:Connection broken for id 62, my id = 70, error = 原因是因为zoo.cfg中server.id不正确. serve ...

  5. base64/62 加解密的实现。

    base64/62加解密代码下载地址: http://files.cnblogs.com/files/Kingfans/base64(62)加解密.zip base64: base62:

  6. /usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’

    /usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’/usr/include/linux/types.h:13: erro ...

  7. [HDU2089]不要62

    [HDU2089]不要62 试题描述 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就 ...

  8. NYOJ题目62笨小熊

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr4AAAK1CAIAAAChInrhAAAgAElEQVR4nO3dO3LjutaG4X8Szj0Qxx

  9. 62个Android Studio小技巧合集

    1书签(Bookmarks) 描述:这是一个很有用的功能,让你可以在某处做个标记(书签),方便后面再跳转到此处. 调用:Menu → Navigate → Bookmarks 快捷键: 添加/移除书签 ...

  10. [ACM_水题] 不要62(hdu oj 2089, 不含62和4的数字统计)

    Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来, ...

随机推荐

  1. JSP解决:Attempt to clear a buffer that&#39;s already been flushed错误(jsp:forward标签跳转空白)

    [摘要:本日正在开辟过程当中发明一个题目:正在页里中应用了jsp:forward扔错Attempt to clear a buffer that's already been flushed!! 百思 ...

  2. drawRect中抗锯齿

    在开始之前,我们需要创建一个DrawRectView 其初始代码为 // // DrawRectView.h // CGContextSetShouldAntialias // // Created ...

  3. Springboot中Aspect实现切面(以记录日志为例)

    前言今天我们来说说spring中的切面Aspect,这是Spring的一大优势.面向切面编程往往让我们的开发更加低耦合,也大大减少了代码量,同时呢让我们更专注于业务模块的开发,把那些与业务无关的东西提 ...

  4. 通过脚本调用MSBuild编译项目时指定Configuration(解決方案配置)和Platform(解決方案平台),Rebuid(重新生成解决方案),Clean(清理解决方案)

    为了方便打包测试,自己PowerShell写了一个编译和发布的脚本,调用msbuild通过命令行来编译当前解决方案 后来发现一个问题,用VS编译解决方案,我通过 项目属性-Build设置 Releas ...

  5. Shader、Draw Call和渲染管线(Rendering Pipeline)

    翻阅了很多资料,也做了不少笔记,决定还是对渲染进行一个总结,以巩固所学的东西. <Real-Time Rendering, Third Edition>   (PDF的配图链接)将一个渲染 ...

  6. too much recursion(太多递归)Uncaught RangeError: Maximum call stack size exceeded BootstrapValidator报错

    在BootstrapValidator中已默认遵守Bootstrap规则,form里的每个输入项目必需包含在类为form-group的标签里,否则BootstrapValidator中定义的field ...

  7. C# ReaderWriterLockSlim 实现

    其实ReaderWriterLockSlim的实现前段时间看了,当时不打算记录下来的,因为它的实现实在System.Core项目里面,而不是mscorlib项目.按照惯例我们还是先看看网上的一些说法吧 ...

  8. grid - 隐式命名网格线名称

    1.隐式的指定网格线反向指定了隐式的网格区域名称,命名的网格区域隐式的命名了网格线名称. 指定网格区域会给网格区域边线添加隐式的网格线名称.这些网格线的命名是基于网格区域来命名,只是在网格区域名称的后 ...

  9. android编码学习

    虽然以下博客有点老,但很清晰,有不明白的基础知识,可以来这里找找. 2015年最新Android基础入门教程目录(完结版) 1. 环境配置 Android stodio gradle配置踩过的坑 An ...

  10. 一个简单的开源PHP爬虫框架『Phpfetcher』

    这篇文章首发在吹水小镇:http://blog.reetsee.com/archives/366 要在手机或者电脑看到更好的图片或代码欢迎到博文原地址.也欢迎到博文原地址批评指正. 转载请注明: 吹水 ...