不要62

杭州人称那些傻乎乎粘嗒嗒的人为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
#include <cstdio>
#include <cstring>
#include <string>
#include <set>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
#define inf 0x3f3f3f3f
ll digit[20];                                //用来存数的位数,及每个数位上的最大值;
ll dp[20][2];                                //存状态
ll dfs(ll per, bool state, bool fp)          //per表示位数,per=4表示在第四位;
{
                                            //state表示状态,if  state=1,表示第per位的前一位是6;
                                            //fp表示在第per位上是否有上限,即在该位的取值为0~9还是0~digit[per];
    if(per==0) return 1;                    //当per为0时,表示已经枚举了一个有意义的数,答案加1;
    if(!fp && dp[per][state]!=-1)           //避免重复计算;
        return dp[per][state];
    ll ret=0, fpmax = fp!=0? digit[per] : 9; //fpmax表示在该位的最大值;

    for(ll i=0; i<=fpmax; i++)
    {
        if((state&&i==2)||i==4)            //当出现4,或者前一位为6,当前位为2时跳过不计;
            continue;
        else
            ret+=dfs(per-1, i==6, i==fpmax && fp);//i==6用来判断递归后前一位是否为6;
    }
    if(fp==0)
        dp[per][state]=ret;
    return ret;
}
ll tao(ll n)
{
    ll per=0;
    memset(digit, 0, sizeof(digit));
    while(n)                                    //计算数的每一位数;
    {
        digit[++per]=n%10;
        n/=10;
    }
    return dfs(per, false, true);
}
int main()
{
    ll n,m;
    memset(dp,-1,sizeof(dp));
    while(~scanf("%lld%lld",&n,&m),n+m)
    {
        printf("%lld\n",tao(m)-tao(n-1));
    }
    return 0;
}

要49

The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the power of the blast would add one point. 
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them? 

Input

The first line of input consists of an integer T (1 <= T <= 10000), indicating the number of test cases. For each test case, there will be an integer N (1 <= N <= 2^63-1) as the description. 

The input terminates by end of file marker. 

Output

For each test case, output an integer indicating the final points of the power.

Sample Input

3
1
50
500

Sample Output

0
1
15

Hint

From 1 to 500, the numbers that include the sub-sequence "49" are "49","149","249","349","449","490","491","492","493","494","495","496","497","498","499",
so the answer is 15.

题意:统计1~n中含有连续49的数字的个数。

#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
ll digit[20];
ll dp[20][2];
ll dfs(ll per, bool state, bool fp)
{
    if(per==0) return 1;
    if(!fp && dp[per][state]!=-1) return dp[per][state];
    ll ret=0, fpmax = fp!=0? digit[per] : 9;

    for(ll i=0; i<=fpmax; i++)
    {
        if( (state&&i==9))
            continue;
            else ret+=dfs(per-1, i==4, i==fpmax && fp);
    }
    if(fp==0) dp[per][state]=ret;
    return ret;
}
ll Cnt(ll n)
{
    ll per=0;
    memset(digit, 0, sizeof(digit));
    while(n)
    {
        digit[++per]=n%10;
        n/=10;
    }
    return dfs(per, false, true);
}
int main()
{

    ll n, m,t;
    cin>>t;
    while(t--)
    {
        cin>>m;
        memset(dp, -1, sizeof(dp));
        ll ans = Cnt(m) ;
        cout << m-ans+1 << endl;
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值