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
题意:给你一个数n,数出[1,n]中含有49的个数。
思路:可以先把[0,r)中不含49的个数求出来,然后用n+1-solve(n+1)就行了。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#define inf 99999999
#define pi acos(-1.0)
#define maxn 1000050
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef long double ldb;
ll dp[65][12];
void init()
{
int i,j,k;
memset(dp,0,sizeof(dp));
for(j=0;j<=9;j++)dp[1][j]=1;
for(i=2;i<=64;i++){
for(j=0;j<=9;j++){
for(k=0;k<=9;k++){
if(j==4 && k==9 )continue;
dp[i][j]+=dp[i-1][k];
} } } }
ll solve(ll x)
{
int wei[70],i,j,len=0;
ll t=x;
while(t){
wei[++len]=t%10;
t/=10;
}
wei[len+1]=0;
ll sum=0;
for(i=len;i>=1;i--){
for(j=0;j<wei[i];j++){
sum+=dp[i][j];
}
if(wei[i+1]==4 && wei[i]==9)break;
}
return sum; } int main()
{
int m,i,j,T;
ll n;
init();
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
printf("%lld\n",n+1-solve(n+1));
}
return 0;
}

最新文章

  1. vue 解决display与 transition冲突
  2. iOS,plist文件、pct文件,工程设置
  3. IO-同步,异步,阻塞,非阻塞
  4. mysql-insert-返回主键id
  5. Java学习笔记之:java运算符
  6. 5、处理模型数据ModelAndView、Map、Model以及@SessionAttributes注解
  7. vss2005使用
  8. selendroid inspector xpth元素定位记录
  9. navicat:cannot create oci environment
  10. 14.4.1 InnoDB Startup Configuration
  11. tcpdf导出pdf数据支持中文的解决方案
  12. Linux项目自动部署
  13. java中System.getProperty()的作用及使用
  14. UVA437-The Tower of Babylon(动态规划基础)
  15. Java --Servlet 32个经典问题
  16. Luogu3587[POI2015]POD - hash + 单调队列
  17. 【洛谷P2384】最短乘积路径
  18. 开始学习tensorflow
  19. Visual Studio 项目模板制作(二)
  20. C++ 实验2:函数重载、函数模板、简单类的定义和实现

热门文章

  1. 一些JavaSE学习过程中的思路整理(主观性强,持续更新中...)
  2. NAS基础知识
  3. docker 容器和镜像的常用命令
  4. 干电池升压5V,功耗10uA
  5. CNN可视化技术总结(一)--特征图可视化
  6. Python編碼格式錯誤解決方案及案例
  7. JavaScript的数据类型和数据类型的检测
  8. Linux网络数据包的揭秘以及常见的调优方式总结
  9. C# 防止程序多开(重复开启)
  10. LOJ2125