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

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.

 
Author
fatboy_cw@WHU
 
Source
 
 
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long LL; LL dp[][];
/**
* dp[i][0],表示长度为i,不存在不吉利数字
* dp[i][1],表示长度为i, 不存在不吉利数字,且最高位为9
* dp[i][2],表示长度为i, 存在不吉利数字
*/ void Init()
{
int i; dp[][] = ;
for(i=; i<; i++)
{
dp[i][] = *dp[i-][] - dp[i-][];
dp[i][] = dp[i-][];
dp[i][] = *dp[i-][] + dp[i-][];
}
} LL Slove(LL n)
{
int i, a[]={}, len=, flag=;
LL n1 = n, ans=; while(n1)
{
a[++len] = n1%;
n1 /= ;
} for(i=len; i>=; i--)
{
ans += dp[i-][]*a[i];
if(flag)///高位已经出现49了,后面随意
ans += dp[i-][]*a[i];
else if(!flag && a[i]>)
ans += dp[i-][];
if(a[i+]== && a[i]==)
flag = ;
} return ans;
}
int main()
{
int T;
Init();
scanf("%d", &T);
while(T--)
{
LL n; scanf("%I64d", &n); printf("%I64d\n", Slove(n+));
}
return ;
}

(数位dp)Bomb (hdu 3555)的更多相关文章

  1. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

  2. Bomb HDU - 3555

    Bomb HDU - 3555 求1~n中含有49数的个数 #include<bits/stdc++.h> #define LL long long using namespace std ...

  3. Bomb HDU 3555 dp状态转移

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题意: 给出一个正整数N,求出1~N中含有数字“49”的数的个数 思路: 采用数位dp的状态转移方程 ...

  4. 数位dp入门 HDU 2089 HDU 3555

    最基本的一类数位dp题,题目大意一般是在a~b的范围,满足某些要求的数字有多少个,而这些要求一般都是要包含或者不包含某些数字,或者一些带着数字性质的要求,一般来说暴力是可以解决这一类问题,可是当范围非 ...

  5. 【数位DP】Hdu 2089:不要62

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. 数位DP入门(A - 不要62 HDU - 2089 &&B - Bomb HDU - 3555 )

    题目链接:https://cn.vjudge.net/contest/278036#problem/A 具体思路:对于给定的数,我们按照位数进行运算,枚举每一位上可能的数,在枚举的时候需要注意几个条件 ...

  7. Bomb HDU - 3555 数位dp

    Code: #include<cstdio> #include<algorithm> #include<cstring> #include<string> ...

  8. 【数位DP】 HDU 4734 F(x)

    原题直通车:HDU 4734 F(x) 题意:F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1, 求0.....B中F[x]<=F[A ...

  9. 【数位DP】Hdu 3652:B-number

    B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  10. 【数位DP】 HDU 4722 Good Numbers

    原题直通车: HDU  4722  Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...

随机推荐

  1. PhotoSphereViewer 全景图

    1网站地址:http://photo-sphere-viewer.js.org/markers.html#demo 2参数中文地址:https://www.cnblogs.com/big-tree/p ...

  2. C++中的set

    总结一下: vector:封装了数组  list:封装了列表  map,set:封装了二叉树 set:用来存储同一类型的数据类型 非关联容器相对关联型容器插入效率高,原因是:不需要内存拷贝和内存移动, ...

  3. PAT 1024 科学计数法 (20)(精简版代码+思路+推荐测试样例)

    1024 科学计数法 (20)(20 分) 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+-][0-9]+, ...

  4. hdu 2444(二分图) The Accomodation of Students

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 大意是给定n个学生,他们之间可能互相认识,首先判断能不能将这些学生分为两组,使组内学生不认识: 现想将学生 ...

  5. RNA测序相对基因表达芯片有什么优势?

    RNA测序相对基因表达芯片有什么优势? RNA-Seq和基因表达芯片相比,哪种方法更有优势?关键看适用不适用.那么RNA-Seq适用哪些研究方向?是否您的研究?来跟随本文了解一下RNA测序相对基因表达 ...

  6. POJ 3621Sightseeing Cows 0/1 分数规划

    Description 作为对奶牛们辛勤工作的回报,Farmer John决定带她们去附近的大城市玩一天.旅行的前夜,奶牛们在兴奋地 讨论如何最好地享受这难得的闲暇. 很幸运地,奶牛们找到了一张详细的 ...

  7. django DEBUG=False

    在django的settings中. 将DEBUG 设置为False. 会出现 #python manage.py runserver 8888 CommandError: You must set ...

  8. hook api实现

    https://www.cnblogs.com/findumars/p/8734116.html https://blog.csdn.net/lonelyrains/article/details/2 ...

  9. Java中的四种内部类

    Java中有四种内部类: 成员内部类:定义在另一个类(外部类)的内部,而且与成员属性和方法平级,故称成员内部类.类比于外部类的非静态方法,如果用static修饰就变成了静态内部类 静态内部类:使用st ...

  10. Python之路(第一篇):Python简介和基础

    一.开发简介 1.开发:      开发语言:               高级语言:python.JAVA.PHP.C#..ruby.Go-->字节码                低级语言: ...