Bomb

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

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.


和 不要62 类似
注意:
1. long long
2.if(a[i+1]==4&&a[i]>=9) flag=1;
不能+d[i-1][0],因为9的特殊性不可能有比9大的个位数使后面可能出现49,天际线就是49了
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
const int N=,INF=1e9+;
typedef long long ll;
inline ll read(){
char c=getchar();ll x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
ll n;
ll d[N][];
void dp(){
d[][]=;
for(int i=;i<=;i++){
d[i][]=*d[i-][]-d[i-][];//!
d[i][]=d[i-][];
d[i][]=*d[i-][]+d[i-][];
//printf("d %d %d\n",d[i][0],d[i][2]);
}
}
ll sol(ll n){
int a[N],len=,flag=;
ll ans=;
while(n) a[++len]=n%,n/=;
a[len+]=;
for(int i=len;i>=;i--){
ans+=d[i-][]*a[i]; if(flag) ans+=a[i]*d[i-][];
else if(a[i]>) ans+=d[i-][];//maybe 49
if(a[i+]==&&a[i]==) flag=;//cannot +d[i-1][0],cause skyline and flag=1
//printf("%d %d %d\n",i,ans,flag);
}
if(flag) ans++;
return ans;
}
int main(){
dp();
int T=read();
while(T--){
n=read();
printf("%lld\n",sol(n));
}
}

HDU3555 Bomb[数位DP]的更多相关文章

  1. hdu---(3555)Bomb(数位dp(入门))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  2. HDU3555 Bomb —— 数位DP

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

  3. hdu3555 Bomb(数位dp)

    题目传送门 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

  4. hdu3555 Bomb 数位DP入门

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...

  5. HDU3555 Bomb 数位DP第一题

    The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...

  6. hdu3555 Bomb (数位dp入门题)

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  7. 【hdu3555】Bomb 数位dp

    题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...

  8. HDU 3555 Bomb 数位dp

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

  9. hud 3555 Bomb 数位dp

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

随机推荐

  1. codevs 1021 玛丽卡(spfa)

    题目描述 Description 麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. 因为她和他们不住在同一个城市,因此她开始准备她的长途旅行. 在这个国家中每两个城市之间最多只有一条路相通,并且我们 ...

  2. php 实现设计模式之 享元模式

    <?php class Book{ public $title; public $author; public function __construct($title,$author){ $th ...

  3. 【系统架构】缓存Memcache 使用原子性操作add,实现并发锁

    原文地址 memcache中Memcache::add()方法在缓存服务器之前不存在key时, 以key作为key存储一个变量var到缓存服务器.我们使用add来向服务器添加一个键值对应,如果成功则添 ...

  4. Lind.DDD.Domain.ISortBehavor~上移与下移

    在进行列表排序时,有个“上移”和“下移”操作,这个一般在内存里完成,然后统一提交到数据库中,对于上移与下移的设计,大叔在LIND.DDD.DOMAIN里有一个ISortBehavor接口,主要是说,如 ...

  5. Maven命令行使用:mvn clean package(打包)

    先把命令行切换到Maven项目的根目录,比如:/d/xxxwork/java/maven-test,然后执行命令:  mvn clean package 执行结果如下: [INFO] Scanning ...

  6. GJM :Unity3D 5.x性能分析工具与应用方法

    原帖地址 http://gad.qq.com/content/coursedetail/7180616 Unity Profiler Unity => Window=>Profiler P ...

  7. form表单提交和ajax表单提交,关于移动端如何通过软键盘上的【搜索】和【前进】进行提交操作

    [文章来源]由于自己对于form研究甚少,所以一直用的都是AJAX进行提交,这次后台提出要用form提交,顺便深入研究一下:之前在做表单的时候,发现input可以通过设置不同的type属性,调用不同的 ...

  8. 原生JS:RegExp对象详解

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  9. MySQL错误(一)

    Host 'localhost' is not allowed to connect to this MySQL server 手贱误操作将root用户删除,解决办法: 找到mysql的配置文件 my ...

  10. js中查找相同的几种函数

    function findInArr(arr,num){ for(var i=0;i<arr.length;i++){ if(arr[i]==num){ return true; } } ret ...