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. 关于ubuntu上无法运行cmd markdown

    环境:ubuntu18.04 直接解压完的cmd markdown,直接点击可执行文件运行,没有反应,在通过终端运行,提示:Cannot find required executable ifconf ...

  2. 甲级1002 A+B for Polynomials (25)

    题目描述: This time, you are supposed to find A+B where A and B are two polynomials. Input Each input fi ...

  3. Java语言课程设计

    一.项目简介 本实验是对图形用户界面,布局管理器的综合应用,理解Java的处理机制,编写独立运行的窗口 二.项目采用技术 GUI,JAVA 三.功能需求分析 1.使用用户图形界面 2.能够实现年月份的 ...

  4. 使用PHP静态变量当缓存的方法

    下面这个PHP的代码实例,功能是帮助用户重置密码,requestResetPassword是接收用户重置密码的请求并且做了相应的检查.为了更好的复用性,我将重置密码的操作单独分配到一个新的resetP ...

  5. ArcGis融合小多边形到相邻多边形

     在有的时候,我们的数据中可能会有许多细小的图斑,这些并不是我们想要的,需要将它们合并到周围的图斑中,如果一个一个手动合并,那工作量之大简直不敢想象.现在借助ArcGIS的Eliminate工具可 ...

  6. 【南开OJ2264】节操大师(贪心+二分+并查集/平衡树)

    好久没更新了,今天就随便写一个吧 题目内容 MK和他的小伙伴们(共n人,且保证n为2的正整数幂)想要比试一下谁更有节操,于是他们组织了一场节操淘汰赛.他们的比赛规则简单而暴力:两人的节操正面相撞,碎的 ...

  7. 【BZOJ 2753 滑雪与时间胶囊】

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 2843  Solved: 993[Submit][Status][Discuss] Descripti ...

  8. 创建dll

    在制作dll的时候,如果全局变量不导出,而函数调用中,包含了全局变量,那么会出现全局变量没有值的问题. add.c #pragma once //强制无签名utf-8 #include "a ...

  9. Clevo P950笔记本加装4G模块

    要补全的电路部分如下(原理图见附件) 这里经过尝试,发现左上角R217,R218不用接,3G_POWER部分不接(包括MTS3572G6.UK3018及电阻电容,3G_PWR_EN实测是3.3V,驱动 ...

  10. Tile Cut~网络流入门题

    Description When Frodo, Sam, Merry, and Pippin are at the Green Dragon Inn drinking ale, they like t ...