hdu2089

链接:hdu2089

Description

  • 杭州人称那些傻乎乎粘嗒嗒的人为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

    题解

  • 模板题
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#define rep(i,l,n)for(register int i=l;i<n;++i)
#define ll long long
using namespace std;
const int N=55;
int a[N];
ll dp[N][2];//当前第i位,前置有或没有6共有多少种情况

int dfs(int pos,int pre,int sta,int limit){
if(pos==-1)return 1;
if(!limit&&dp[pos][sta]!=-1)return dp[pos][sta];
int up=limit?a[pos]:9;
int tmp=0;
rep(i,0,up+1){
if(pre==6&&i==2)continue;
if(i==4)continue;
tmp+=dfs(pos-1,i,i==6,limit&&a[pos]==i);
}
if(!limit)dp[pos][sta]=tmp;
return tmp;
}

int solve(int x){
int cnt=0;
while(x){
a[cnt++]=x%10;
x/=10;
}
return dfs(cnt-1,-1,0,true);
}

int main(){
int l,r;
memset(dp,-1,sizeof(dp));//不管l与r怎么给 已经计算出来的状态是不会改变的
while(~scanf("%d%d",&l,&r)){
if(l==0&&r==0)break;
printf("%d\n",solve(r)-solve(l-1));
}
}