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. javaweb学习总结(三十八)——事务

    一.事务的概念 事务指逻辑上的一组操作,组成这组操作的各个单元,要不全部成功,要不全部不成功. 例如:A——B转帐,对应于如下两条sql语句  update from account set mone ...

  2. Java动态代理全面分析

    代理模式 解说:给某一个对象提供一个代理,并由代理对象控制对原对象的引用: 代理模式需要以下几个角色: 1  主题:规定代理类和真实对象共同对外暴露的接口: 2  代理类:专门代理真实对象的类: 3 ...

  3. php 实现设计模式之 建造者模式

    <?php /** * 建造者模式 * ------------- * 定义:将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. * 类型:创建类模式 * 四个要素: * ...

  4. ASP.NET MVC开发中常见异常及解决方案

    ASP.NET MVC4入门到精通系列目录汇总 NHibernate:no persister for 异常 1.配置文件后缀名写错 mapping file 必须是.hbm.xml结尾 2.Web. ...

  5. GJM : C#语言学习笔记

    --------------------------------------C#--------------------------------------if (tom == null) tom = ...

  6. 从头开始搭建分布式日志平台的docker环境

    上篇(spring mvc+ELK从头开始搭建日志平台)分享了从头开始搭建基于spring mvc+redis+logback+logstash+elasticsearch+kibana的分布式日志平 ...

  7. iscroll总结

    iScroll基本信息 官网:http://cubiq.org/iscroll-4 更新:2012.07.14 版本:v4.2.5 兼容:iPhone/Ipod touch >=3.1.1, i ...

  8. arcgis地图数据集合

    一.全国的ArcGIS地图SHP格式数据,覆盖的图层信息量基本齐全,除了ArcGIS之外,其他GIS软件(superMap和MapGIS.MapInfo等等)也是用之,适合为GIS开发提供数据素材. ...

  9. Activity详解二 activity数据传递

    首先看效果图: 1.Bundle类的作用 Bundle类用作携带数据,它类似于Map,用于存放key-value名值对形式的值.相对于Map,它提供了各种常用类型的putXxx()/getXxx()方 ...

  10. jQuery与Zepto的异同

    一,同: Zepto最初是为移动端开发的库,是jQuery的轻量级替代品,因为它的API和jQuery相似,而文件更小.Zepto最大的优势是它的文件大小,只有8k多,是目前功能完备的库中最小的一个, ...