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. luogu P1886 滑动窗口(单调队列

    题目描述 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值. 例如: The array i ...

  2. 识别SQL Server 性能杀手

    性能优化的重点在于识别定位问题,预先了解主要的性能杀手,能够更快的定位到问题并将工作集中在可能的原因之上. SQL SERVER性能杀手主要集中在如下几类: 1.1   低质量的索引 低质量的索引通常 ...

  3. http://www.cnblogs.com/shihaiming/

    原文:http://www.bubuko.com/infodetail-917303.html 右击项目,点击Run as,如下图: 即可看到有很多现有的maven命令,点击即可运行,并在控制台可以看 ...

  4. android Activity生命周期的例子

    package com.example.yanlei.yl2; import android.app.AlertDialog; import android.content.DialogInterfa ...

  5. Map与object的区别

    Map 对象保存键值对.任何值(对象或者原始值) 都可以作为一个键或一个值. 语法 new Map([iterable]) 参数 iterable Iterable 可以是一个数组或者其他 itera ...

  6. IntelliJ IDEA 默认需要进行maven的设置

    IntelliJ IDEA 默认需要进行maven的设置 需要指定maven的地址,指定settings.xml的地址: 可以默认的在user/.m2/下面放一个settings.xml文件: 学习: ...

  7. UVA 1482 - Playing With Stones(SG打表规律)

    UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...

  8. SolidEdge如何打开或关闭自动标注尺寸

    工具-聪慧-自动标注尺寸                    

  9. Vue 建立工程

    npm install -g vue npm install -g vue-cli vue init webpack my-project cd my-project npm isntall npm ...

  10. aip接口中对url参数md5加密防篡改的原理

    目前网上所有开放api的网站中,数据的调用都是采用同一种方式,即: http:www.xxx.com/aa=1&bb=2...,原后对这些参数按字典顺序排序后进行md5加密,将md5加密串与接 ...