I. GZP and CS

GZP love to play Counter-Strike(CS).
One day GZP was playing a mod of CS.
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 "96", the power of the blast would add one point.
Now GZP knows the number N. Only when the computing result of the final points of the power by GZP is correct can he attain success.Can you help him?
 

Input

The first line of input consists of an integer T (1 <= T <= 100), indicating the number of test cases.  For each test case, there will be an integer N (1 <= N <= 2^63-1) as the description.
 

Output

For each test case, output an integer indicating the final points of the power.
 

Sample Input

3
1
100
500

Sample Output

0
1
5

Hint

From 1 to 500, the numbers that include the sub-sequence "96" are "96","196","296","396","496",so the answer is 5.

题意

问[1,n]中有多少个数中包含96;

思路:

数位dp的题,跟有一道hdu的数位dp一样;哎,还没理解记忆化搜索的写法;有时间看看去;

AC代码

#include <bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e6+5e5;
LL dp[][],n;
int b[];
//dp[i][0]表示长度<=i包含96的个数;
//dp[i][1]表示长度为i不包含96但开头为6的个数
//dp[i][2]表示<=i不包含96的个数;
int fun()
{
mst(dp,);
dp[][]=1LL;
for(int i=;i<;i++)
{
dp[i][]=dp[i-][]*+dp[i-][];
dp[i][]=dp[i-][];
dp[i][]=dp[i-][]*-dp[i-][];
}
}
int main()
{
int t;
scanf("%d",&t);
fun();
while(t--)
{
scanf("%lld",&n);
LL temp=n,ans=;
int cnt=;
while(temp)
{
b[cnt++]=temp%;
temp/=;
}
b[cnt]=;
int flag=;
for(int i=cnt;i>;i--)
{
ans+=dp[i-][]*(LL)b[i];
if(flag)//如果前边已经出现了96那么就还要加上后面不含96的方案数;
{
ans+=dp[i-][]*b[i];
}
if(b[i+]==&&b[i]==)
{
flag=;
}
}
if(flag)ans++;//如果96出现的位置后面全是0
printf("%lld\n",ans);
}
return ;
}

西交校赛 I. GZP and CS(数位dp)的更多相关文章

  1. 西交校赛 F. GZP and Poker

    F. GZP and Poker GZP often plays games with his friends.Today they went to a board game.There are n ...

  2. ZOJ 3949 (17th 浙大校赛 B题,树型DP)

    题目链接  The 17th Zhejiang University Programming Contest Problem B 题意  给定一棵树,现在要加一条连接$1$(根结点)和$x$的边,求加 ...

  3. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)

    题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...

  4. The 2018 ACM-ICPC上海大都会赛 J Beautiful Numbers (数位DP)

    题意:求小于等于N且能被自己所有位上数之和整除的数的个数. 分析:裸的数位dp.用一个三位数组dp[i][j][k]记录:第i位,之前数位之和为j,对某个mod余数为k的状态下满足条件的个数.这里mo ...

  5. 2019牛客多校第七场H Pair 数位DP

    题意:给你一个3个数A, B, C问有多少对pair(i, j),1 <= i <= A, 1 <= j <= B, i AND j > C或 i XOR j < ...

  6. 牛客多校第七场H Pair 数位dp理解

    Pair 题意 给出A B C,问x取值[1,A]和y取值[1,B]存在多少组pair<x,y>满足以下最小一种条件,\(x \& y >c\),\(x\) xor \(y& ...

  7. 2014上半年acm总结(1)(入门+校赛)

    大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干=  = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...

  8. 2014哈商大ICPC/ACM校赛解题报告

    被debug邀请去參加校赛,哎,被虐..我对不起工大.. 由于本人不搞ACM,算法处于HelloWorld水准.. 虽然题目除了鸟不拉屎星人之外都非常水,但我能做到这个程度,全然是超水平发挥了.. 数 ...

  9. xdoj 2020校赛复盘

    平时写东西都不喜欢复盘,这肯定不是一个好习惯,感觉每次花好几个小时甚至好几天写题目然后没写出来也不去看题解是一种很蠢的行为( 花了这么久时间打校赛,虽然水平很low,数据结构也不太会用,还是记录一下自 ...

随机推荐

  1. BZOJ 1090 字符串折叠(Hash + DP)

    题目链接 字符串折叠 区间DP.$f[l][r]$为字符串在区间l到r的最小值 正常情况下 $f[l][r] = min(f[l][r], f[l][l+k-1]+f[l+k][r]);$ 当$l$到 ...

  2. ubuntu下安装翻译软件

    原文: http://sixipiaoyang.blog.163.com/blog/static/6232358820144146386437/ Ubuntu下常用的翻译软件有StarDict,Gol ...

  3. Centos7安装遇到的问题及详解

    1.虚拟机中选择的是NAT模式,我的笔记本电脑是拨号上网,用桥接模式,找不到网卡,在windows的dos界面用ipconfig查看的结果 PPP适配器 宽带连接:IPv4 地址 . . . . . ...

  4. SpringBoot中mybatis的自动生成

    1.在pom文件中加入自动生成的插件 <!-- mybatis generator 自动生成代码插件 --> <plugin> <groupId>org.mybat ...

  5. Android判断屏幕锁屏的方法总结

    由于做一个项目,需要判断屏幕是否锁屏,发现网上方法很多,但是比较杂,现在进行总结一下: 总共有两类方法: 一.代码直接判定 二.接收广播 现在先说第一类方法(代码直接判定): 1.通过PowerMan ...

  6. C++与Java语法上的不同

    最近学习算法和刷题基本都是用C++写的程序,在这个过程中,发现C++和Java在语法上有很多相同点,但也有很多不同点,而这些不同点对于已经掌握Java的程序员来说,理解C++代码可能会有些吃力甚至困难 ...

  7. javascript 在线文本编辑器

    javascript 在线文本编辑器实现代码. 效果例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcGhwZmVuZ2h1bw==/font/5 ...

  8. go test test & benchmark

    开发程序其中很重要的一点是测试,我们如何保证代码的质量,如何保证每个函数是可运行,运行结果是正确的,又如何保证写出来的代码性能是好的,我们知道单元测试的重点在于发现程序设计或实现的逻辑错误,使问题及早 ...

  9. Eclipse打包Android项目时用到proguard.cfg后,出现的Warning:can&#39;t find referenced class问题的解决方式

    Warning: can't find superclass or interface Warning: can't find referenced class 这两个问题的解决方法: 1.要把你项目 ...

  10. 线程池ThreadPoolExecutor分析

    线程池.线程池是什么,说究竟,线程池是处理多线程的一种形式,管理线程的创建,任务的运行,避免了无限创建新的线程带来的资源消耗,可以提高应用的性能.非常多相关操作都是离不开的线程池的,比方android ...