Bomb

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 11029    Accepted Submission(s): 3916

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.

 
/**
题意:1~n之间有多少数包含49
做法:数位dp
///dp[i][0] 表示当前位没有49
///dp[i][1] 表示当前位是以9开头
///dp[i][2] 表示含有49
设sum = 0;
对于n进行从高到低进行的扫描
对于当前位 sum += dp[i-1][2]*mmap[i] 对于i-1满足要求的
如果当前的位数 > 4 并且没有包含49 那么 sum += dp[i-1][1];
如果当前已经有49了 那么 sum += dp[i-1][0] * mmap[i];
**/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
long long dp[][];
int digit[];
///dp[i][0] 表示当前位没有49
///dp[i][1] 表示当前位是以9开头
///dp[i][2] 表示含有49
int main()
{
memset(dp, , sizeof(dp));
dp[][] = ;
for(int i = ; i < ; i++) ///预处理 很好理解
{
dp[i][] = dp[i - ][] * - dp[i - ][];
dp[i][] = dp[i - ][];
dp[i][] = dp[i - ][] * + dp[i - ][];
}
int t;
cin >> t;
while(t--)
{
int len = , last = ;
long long ans = ;
unsigned long long n = ;
cin >> n;
n++;
memset(digit, , sizeof(digit));
while(n)
{ digit[++len] = n % ;
n /= ;
}
bool flag = false;
for(int i = len; i >= ; i--)
{
ans += dp[i - ][] * digit[i]; ///当前位的可能
if(flag)
{
ans += dp[i - ][] * digit[i]; ///如果已经含有49 加上I-1个不符合要求的个数
}
if(!flag && digit[i] > ) //当前位 > 4 以为前一位已经是9了所以包含49
{
ans += dp[i - ][];
}
if(last == && digit[i] == ) ///包含49
{ flag = true;
}
last = digit[i]; ///标记上一位
}
cout << ans << endl;
}
return ;
}

HDU-3555的更多相关文章

  1. 数位DP入门之hdu 3555 Bomb

    hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...

  2. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  3. 递推、数位DP解析(以HDU 2089 和 HDU 3555 为例)

    HDU 2089 不要62 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2089 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人 ...

  4. Bomb HDU - 3555 (数位DP)

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

  5. Bomb HDU - 3555

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

  6. HDU(3555),数位DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others ...

  7. HDU 3555 Bomb 数位dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...

  8. HDU 3555 Bomb (数位DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 题目大意:从0开始到给定的数字N所有的数字中遇到“49”的数字的个数. Sample Input ...

  9. (数位dp)Bomb (hdu 3555)

    http://acm.hdu.edu.cn/showproblem.php?pid=3555     Problem Description The counter-terrorists found ...

  10. Bomb HDU 3555 dp状态转移

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

随机推荐

  1. Linux---CentOS 定时执行脚本配置

    非常多时候我们有希望server定时去运行一个脚本来触发一个操作.比方使用七牛的工具上传,假设同步文件中面有新添加一个文件,这个时候我们能够提供定时脚本去完毕我们须要的同步命令(七牛的qrsbox工具 ...

  2. 玩lua

    https://my.oschina.net/wangxuanyihaha/blog/186401

  3. 数据结构—栈(Stack)

    栈的定义--Stack 栈是只允许在末端进行插入和删除的线性表.栈具有后进先出的特性(LIFO ,Last In Fast Out). 学过数据结构的人都知道:栈可以用两种方式来实现,一种方法是用数组 ...

  4. hdu 1133 Buy the Ticket (大数+递推)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. LeetCode -- Merge Two Sorted Linked List

    Question: Merge two sorted linked lists and return it as a new list. The new list should be made by ...

  6. [转载] Win7下MATLAB 7.0下载地址和详细安装

    移步http://blog.csdn.net/feecooling/article/details/7525140 MATLAB中文手册命令汇总http://wenku.baidu.com/view/ ...

  7. 2017博普杯 东北大学邀请赛(B. Drink too much water)(贪心+树链剖分)

    题目地址:https://oj.neu.edu.cn/problem/1204 题目大意: 其实就是树上的线段覆盖, 给出一棵n个结点的树,然后给出树上的一些路径进行覆盖,然后要求选取最少的点,能够把 ...

  8. BZOJ4008. [HNOI2015]亚瑟王 期望概率dp

    看到这道题想什么? 一个好转移的状态由于T最多444所以把每个点控制在O(400000)以内,所以对于n和r最多乘一次因此猜f[n][r],f[r][n],首先一轮一轮的搞不好转移,那么先想一想f[n ...

  9. Reasons to use innodb_file_per_table

    When working with InnoDB, you have two ways for managing the tablespace storage: Throw everything in ...

  10. D. Sorting the Coins

    Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins togeth ...