杭州人称那些傻乎乎粘嗒嗒的人为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. JAVA自学笔记11

    JAVA自学笔记11 1:Eclipse的安装 2:用Eclipse写一个HelloWorld案例,最终在控制台输出你的名字 A:创建项目 B:在src目录下创建包.cn.itcast C:在cn.i ...

  2. delphi开源JWT

    delphi开源JWT 开源GIT地址:https://github.com/paolo-rossi/delphi-jose-jwt JSON Web Token (JWT)是一个开放标准(RFC 7 ...

  3. thymeleaf学习笔记

    1.${@dict.hello().fatherName} 显示对象的属性2.${@dict.hello()[0].fatherName} 显示列表对象的属性3.<div th:object=& ...

  4. RestTemplate发送请求并携带header信息 RestTemplate post json格式带header信息

    原文地址:  http://www.cnblogs.com/hujunzheng/p/6018505.html RestTemplate发送请求并携带header信息   v1.使用restTempl ...

  5. python3 cookie

    最近再次学习python,本来就是一个菜鸟,我按照 Python CGI编程 发现读cookie 读取不了,后来发现它这种写的方式也不怎么靠谱. Python中Cookie模块(python3中为ht ...

  6. Apache shiro如何实现一个账户同一时刻只有一个人登录

    继承AuthorizingRealm类,重写方法doGetAuthenticationInfo /** * 认证(登录时调用) */ @Override protected Authenticatio ...

  7. 获得最近一天的提交,并使用winscp上传到服务器

    @echo off D:\dev\Git\bin\git.exe pull origin master D:\dev\Git\bin\git.exe add -A D:\dev\Git\bin\git ...

  8. git强制提交本地分支覆盖远程分支

    git push origin 分支名 --force eg: cd 代码目录 git push origin master --force 运行结果: Total 0 (delta 0), reus ...

  9. VC 预定义宏

    列出预定义的 ANSI C和C++ Microsoft实现宏. 编译器识别预定义的ANSI C宏,并且Microsoft C++实现提供几个更多.这些宏不带参数,并且不能重定义.下面列出的某些预定义的 ...

  10. Windows系统下安装zabbix客户端

    简单介绍如何在windows系统下安装zabbix客户端 1. 首先下载和zabbix服务端大版本相同的windows客户端    例如我服务端安装的是zabbix-3.4.14.tar.gz     ...