hdu3555 Bomb(要49)

Problem Description
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
题意:给你一个数n,数出[1,n]中含有49的个数。
思路:可以先把[0,r)中不含49的个数求出来,然后用n+1-solve(n+1)就行了。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#define inf 99999999
#define pi acos(-1.0)
#define maxn 1000050
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef long double ldb;
ll dp[65][12];
void init()
{
    int i,j,k;
    memset(dp,0,sizeof(dp));
    for(j=0;j<=9;j++)dp[1][j]=1;
    for(i=2;i<=64;i++){
        for(j=0;j<=9;j++){
            for(k=0;k<=9;k++){
                if(j==4 && k==9 )continue;
                dp[i][j]+=dp[i-1][k];
            }


        }


    }




}
ll solve(ll x)
{
    int wei[70],i,j,len=0;
    ll t=x;
    while(t){
        wei[++len]=t%10;
        t/=10;
    }
    wei[len+1]=0;
    ll sum=0;
    for(i=len;i>=1;i--){
        for(j=0;j<wei[i];j++){
            sum+=dp[i][j];
        }
        if(wei[i+1]==4 && wei[i]==9)break;
    }
    return sum;


}



int main()
{
    int m,i,j,T;
    ll n;
    init();
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld",&n);
        printf("%lld
",n+1-solve(n+1));
    }
    return 0;
}


原文地址:https://www.cnblogs.com/herumw/p/9464834.html