zoukankan      html  css  js  c++  java
  • HDOJ 2089 不要62



    不要62

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 13741    Accepted Submission(s): 4417


    Problem 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
     

    Author
    qianneng
     

    Source
     

    Recommend
    lcy
      


    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    typedef long long int LL;

    LL dp[105][3];
    ///0--没有62没有4   1--没有62没有4但前一位是6   2--有62或4
    int bit[100];
    LL a,b;

    LL dfs(int pos,int s,bool limit)
    {
        if(pos==-1)
            return s==2;
        if(limit==false&&dp[pos][s]!=-1)
            return dp[pos][s];
        int end=limit?bit[pos]:9;
        LL ans=0;
        for(int i=0;i<=end;i++)
        {
            int news=s;
            if(i==4)
                news=2;
            else if(s==0&&i==6)
                news=1;
            else if(s==1&&i==2)
                news=2;
            else if(s==1&&i==6)
                news=1;
            else if(s==1&&i!=2)
                news=0;
            ans+=dfs(pos-1,news,limit&&i==end);
        }
        if(limit==false)
            dp[pos][s]=ans;
        return ans;
    }

    int main()
    {
        while(scanf("%I64d%I64d",&a,&b)!=EOF)
        {
            if((a||b)==0break;
            LL all=b-a+1;
            int len=0;a--;
            memset(dp,-1,sizeof(dp));
            while(a)
            {
                bit[len++]=a%10;
                a/=10;
            }
            LL A=dfs(len-1,0,true);
            len=0;
            while(b)
            {
                bit[len++]=b%10;
                b/=10;
            }
            LL B=dfs(len-1,0,true);
            printf("%I64d ",all-(B-A));
        }

        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Codeblocks )

  • 相关阅读:
    android 图片加载库 Glide 的使用介绍
    Android Glide数据更新及内存缓存、硬盘缓存清理
    Android中<meta-data>的使用
    分层,工厂模式,依赖注入控制反转
    Asp.Net_Web身份验证
    aspx后缀映射成html
    网站跳舞人代码
    Sqlerver_各类函数
    Sqlserver_时间用法
    Sqlserver_视图
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350847.html
Copyright © 2011-2022 走看看