[HDU3555]Bomb
[HDU3555]Bomb
试题描述
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?
输入
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.
输出
For each test case, output an integer indicating the final points of the power.
输入示例
输出示例
数据规模及约定
见“输入”
题解
裸数位 dp,f[i][j] 表示前 i 位最高位为数字 j 的数中,包含“49”的个数。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std;
#define LL long long LL read() {
LL x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 21
LL f[maxn][maxn], ten[maxn]; int num[maxn], cnt;
LL sum(LL x) {
cnt = 0; LL orx = x;
while(x) num[++cnt] = x % 10, x /= 10;
LL sum = 0;
for(int i = cnt; i; i--) {
for(int j = 0; j < num[i]; j++) sum += f[i][j];
if(i < cnt && num[i+1] == 4 && num[i] == 9) {
sum += orx % ten[i-1] + 1; break;
}
}
return sum;
} int main() {
ten[0] = 1;
for(int i = 1; i < maxn; i++) ten[i] = ten[i-1] * 10;
for(int i = 1; i < maxn - 1; i++)
for(int j = 0; j <= 9; j++)
for(int k = 0; k <= 9; k++) {
if(k == 4 && j == 9) f[i+1][k] += ten[i-1];
else f[i+1][k] += f[i][j];
} int T = read();
while(T--) {
LL n = read();
printf("%lld\n", sum(n));
} return 0;
}
打这种题最好写一发暴力。。。
[HDU3555]Bomb的更多相关文章
- HDU3555 Bomb[数位DP]
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- hdu3555 Bomb (记忆化搜索 数位DP)
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu---(3555)Bomb(数位dp(入门))
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
- HDU3555 Bomb 数位DP第一题
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- 【数位dp】hdu3555 Bomb
题意就是找0到n有多少个数中含有49.数据范围接近10^20 DP的状态是2维的dp[len][3]dp[len][0] 代表长度为len不含49的方案数dp[len][1] 代表长度为len不含49 ...
- [暑假集训--数位dp]hdu3555 Bomb
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- HDU3555 Bomb —— 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu3555 Bomb(数位dp)
题目传送门 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
- hdu3555 Bomb (数位dp入门题)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...
随机推荐
- 【原】jquery图片预览
平时我们在做图片上传的时候,如果可以让用户选择图片的时候,看到图片的效果,那这样用户体验会好很多,因为用户可以就可以决定是否继续用这张图片,尤其是和ajaxuploadfile结合使用的时候,图片的预 ...
- asp.net中的窗口弹出实现,包括分支窗口 . ASP.NET返回上一页面实现方法总结 .
返回上一页的这个东东在我们做项目的时候一般是用于填写完表单后确认的时候,有对原来输入的数据进行修改或者更新时用的,或者是因为网站为了方便浏览者而有心添加的一个东东,一般这种功能的实现在ASP.NET中 ...
- Mysql事务,并发问题,锁机制
.什么是事务 事务是一条或多条数据库操作语句的组合,具备ACID,4个特点. 原子性:要不全部成功,要不全部撤销 隔离性:事务之间相互独立,互不干扰 一致性:数据库正确地改变状态后,数据库的一致性约束 ...
- Runtime类
Runtime类表示运行时的操作类,是一个封装了JVM进程的类,每一个JVM都对应着一个Runtime类的实例,此实例由JVM运行时为其实例化. //========================= ...
- Unity3D PerRendererData
http://nordicedu.com/tkokblog/wordpress/?tag=perrendererdata MaterialPropertyBlock and SpriteRendere ...
- json最简单的跨域
html代码 <html> <head> <title>index.html</title> <script type="text/ja ...
- Ftp软件
http://www.xlightftpd.com/cn/index.htm FileZilla Server官网:http://www.filezilla-project.org/
- centos 7.0 编译安装mysql 5.6.22 再次总结 成功编译安装~ 越来越熟练了~
查找php.ini文件所在位置 [root@localhost /]# find -name php.ini ./usr/etc/php/etc/php.ini mysql官网的安装说明http:// ...
- phpStudy 创建多个站点,绑定域名
默认情况下,phpStudy 的站点根目录是在它自己的WWW目录,比如 F:\phpStudy\WWW,访问的地址可以是 http://127.0.0.1/ 或 http://localhost/ ...
- Jenkins入门总结
Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 1.持续的软件版本发布/测试项目. 2.监控外部调用执行的工作 在网上貌似没有找到Jenkins的中文的太多的文 ...