题意:http://acm.hdu.edu.cn/showproblem.php?pid=3555

比不要62还要简单  只不过在long long 上面注意些

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 106
#define Lson rood<<1
#define Rson rood<<1|1
LL dp[63][11][3],d[63];///大数一定要用LL 避免出错也可用LL
LL dfs(int now,int up,int falg,int fp)
{
    if(now==1) return falg;
    if(!fp&&dp[now][up][falg]!=-1) return dp[now][up][falg];
    LL ans=0;
    int ma=fp?d[now-1]:9;
    for(int i=0;i<=ma;i++)///标记是否出现49
        ans+=dfs(now-1,i,falg||(up==4&&i==9),fp&&ma==i);
    if(!fp&&dp[now][up][falg]==-1) dp[now][up][falg]=ans;
    return ans;
}
LL calc(LL x)
{
    LL xxx=x;
    int len=0;
    while(xxx)
    {
        d[++len]=xxx%10;
        xxx/=10;
    }
    LL sum=0;
    for(int i=0;i<=d[len];i++)
        sum+=dfs(len,i,0,i==d[len]);
    return sum;
}
int main()
{
    int T;
    LL n;
    scanf("%d",&T);
    memset(dp,-1,sizeof(dp));
    while(T--)
    {
        scanf("%lld",&n);
        printf("%lld\n",calc(n));
    }
    return 0;
}

 

posted on 2017-10-31 11:04  云胡不喜。  阅读(128)  评论(0编辑  收藏  举报