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