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.

 
Author
fatboy_cw@WHU
 
Source
 
 
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long LL; LL dp[][];
/**
* dp[i][0],表示长度为i,不存在不吉利数字
* dp[i][1],表示长度为i, 不存在不吉利数字,且最高位为9
* dp[i][2],表示长度为i, 存在不吉利数字
*/ void Init()
{
int i; dp[][] = ;
for(i=; i<; i++)
{
dp[i][] = *dp[i-][] - dp[i-][];
dp[i][] = dp[i-][];
dp[i][] = *dp[i-][] + dp[i-][];
}
} LL Slove(LL n)
{
int i, a[]={}, len=, flag=;
LL n1 = n, ans=; while(n1)
{
a[++len] = n1%;
n1 /= ;
} for(i=len; i>=; i--)
{
ans += dp[i-][]*a[i];
if(flag)///高位已经出现49了,后面随意
ans += dp[i-][]*a[i];
else if(!flag && a[i]>)
ans += dp[i-][];
if(a[i+]== && a[i]==)
flag = ;
} return ans;
}
int main()
{
int T;
Init();
scanf("%d", &T);
while(T--)
{
LL n; scanf("%I64d", &n); printf("%I64d\n", Slove(n+));
}
return ;
}

最新文章

  1. substr 与 substring 的区别
  2. 最近开发的ECG项目
  3. CentOs7 网卡出现问题Job for network.service failed
  4. Window.open()方法参数详解
  5. python数字图像处理(7):图像的形变与缩放
  6. RDBMS vs. NoSQL 合作还是竞争
  7. DIV与IDIV的用法
  8. unity3D与网页的交互
  9. uvalive4327(单调队列优化)
  10. 转化秒数为正规的时间格式{NSString格式的秒数转成NSDate格式后再以NSString形式输出)
  11. CentOS 7 服务器配置--配置iptables防火墙
  12. jQuery 遍历 – 同胞(siblings)
  13. [Swift]LeetCode217. 存在重复元素 | Contains Duplicate
  14. react - web + webpack4 从0构建
  15. day17递归函数(二分法查找)
  16. 关于windows 7 安装Django和基本使用命令
  17. [Spark][python]从 web log 中提取出 UserID 作为key 值,形成新的 RDD
  18. ASP.NET 表单验证方法与客户端(浏览器)服务器交互机制的故事
  19. HDU 3365 New Ground (计算几何)
  20. Python 递归返回树形菜单JSON串 &lt;flask&gt;

热门文章

  1. code first 添加外键时,与原有的数据冲突ALTER TABLE 语句与 FOREIGN KEY 约束&quot;FK_XXXXX&quot;冲突
  2. 前端基础之JavaScript day51
  3. Linux apt-get命令
  4. 解决sublime3不能编辑插件default settings的问题
  5. 差异表达分析之FDR
  6. 基因组表达分析:如何选择RNA-seq vs. 芯片
  7. python爬虫 urllib库基本使用
  8. .net利用NPOI生成excel文件
  9. On the internet, nobody known you are a dog !
  10. spring 学习 一 spring 介绍