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. UVA 11880 Ball in a Rectangle(数学+平面几何)

    Input: Standard Input Output: Standard Output � There is a rectangle on the cartesian plane, with bo ...

  2. HDU 4588 Count The Carries(数学统计)

    Description One day, Implus gets interested in binary addition and binary carry. He will transfer al ...

  3. WebStorm强大的调试JavaScript功能(转载)

    一.JavaScript的调试 目前火狐和Chrome都具备调试JavaScript的功能,而且还是相当的强大.如果纯粹是用浏览器来进行js调试的话,我比较喜欢用火狐.火狐可以安装各种插件,真的是非常 ...

  4. ActiveMQ+Zookeeper集群配置文档

    Zookeeper + ActiveMQ 集群整合配置文档 一:使用ZooKeeper实现的MasterSlave实现方式 是对ActiveMQ进行高可用的一种有效的解决方案, 高可用的原理:使用Zo ...

  5. ActiveMQ入门代码

    Hello world程序演示: 生产者: package com.mq.helloworld; import javax.jms.Connection; import javax.jms.Conne ...

  6. BZOJ2437 NOI2011兔兔与蛋蛋(二分图匹配+博弈)

    首先将棋盘黑白染色,不妨令空格处为黑色.那么移动奇数次后空格一定处于白色格子,偶数次后空格一定处于黑色格子.所以若有某个格子的棋子颜色与棋盘颜色不同,这个棋子就是没有用的.并且空格与某棋子交换后,棋子 ...

  7. Charles 抓包发现自动跳转为https 问题梳理

    今天遇到个有点意思的问题.特此记录. 业务场景: 做了一个页面,但是对外是挂载在京东主站上.如:www.jd.com/yifu/123456.html. 现场情况: 在本地/测试环境/预发环境中,每次 ...

  8. 【题解】Bzoj2560串珠子

    挺强的……容斥+状压DP.首先想到如果可以求出f[k],f[k]代表联通状态为k的情况下的合法方案数,则f[k] = g[k] - 非法方案数.g[k]为总的方案数,这是容易求得的.那么非法方案数我们 ...

  9. CF#366 704D Captain America 上下界网络流

    CF上的题,就不放链接了,打开太慢,直接上题面吧: 平面上有n个点, 第 i 个点的坐标为 ($X_i ,Y_i$), 你需要把每个点染成红色或者蓝色, 染成红色的花费为 r , 染成蓝色的花费为 b ...

  10. Jsp上传组件Smartupload介绍

    <form action="UploadServlet" enctype="multipart/form-data" method="post& ...