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. 三类(创结行),23种设计模式,速记理解法!PHP

    一,创建型设计模式 1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了.麦当劳 ...

  2. 属性font-family:Font property font-family does not have generic default

    以前定义字体都是用的常用的字体,也没注意过会有这个提示,昨天在写界面的时候重新定义了一个本地没有的字体,发现会有提示. W3C的文档: font-family:<family-name>, ...

  3. TreeView 与 ListView

    ListView: viewStyle icon 大图标 list  列表,单列 report 报表 smallIcon 小图标 largeImage 与icon对应 smallImage 与saml ...

  4. FIREDAC字段类型映射

    为什么需要字段类型映射? 作为通用型数据引擎的FIREDAC或者UNIDAC,驱动某一种数据库以后,总有一些数据库的一些字段类型,数据引擎不能识别,反应到程序中就是数据引擎不能正确地读取该字段的值 . ...

  5. 【Gradle】配置中引用的jar包版本后面自动加冒号导致引入jar包失败的问题/gradle中引用jar包版本不一致的问题/gradle中引用jar失败的问题 解决方法

    idea中 gradle中 引用jar包,版本后面默认加:的问题 gradle中引用jar包版本不一致的问题 gradle中引用jar失败的问题 如上题目所示,三个问题其实都是同一样的简单又恶心,因为 ...

  6. bootstrap -- col-sm-6 和 col-xs-6

  7. ubuntu 添加和删除用户

    Without a home directory sudo useradd myuser With home directory sudo useradd -m myuser Then set the ...

  8. Android URL中文处理

    不多说,贴上代码.大家都明确 import java.io.File; import android.net.Uri; public class Transition { /** * @param u ...

  9. virtual member functions(单一继承情况)

    virtual member functions的实现(就单一继承而言): 1.实现:首先会给有多态的class object身上增加两个members:一个字符串或数字便是class的类型,一个是指 ...

  10. centos下的hadoop集群实现ssh的无密码登陆

    CentOS 下SSH无密码登录的配置 最近学习Hadoop.它要求各节点之间通过SSH无密码登录,配置SSH的时候费了一番功夫,记录下来,以备忘. 配置SSH无密码登录需要3步: 1.生成公钥和私钥 ...