Problem Description
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.
 
Input
Process till EOF. In each line, there is one positive integer n(1 <= n <= 1000000000).
 
Output
Print each answer in a single line.
 
Sample Input
13
100
200
1000
 
Sample Output
1
1
2
2
 
Author
wqb0039
 
Source
 

题解:

设f[i][j][r][0/1]表示i位数(可含前导0)第一位为j,mod13的余数是r,有没有出现13(0/1)的数有几个

code:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxl=;
const int maxnum=;
const int rest=;
int n,power[maxl],f[maxl][maxnum][rest][],a[maxl];
void init(){
power[]=;
for (int i=;i<=;i++) power[i]=power[i-]*%;
f[][][][]=;
for (int i=;i<=;i++) for (int j=;j<=;j++)
for (int k=;k<=;k++) for (int r=;r<;r++){
int tmp=(r+j*power[i])%;
if (!(j==&&k==)) f[i][j][tmp][]+=f[i-][k][r][];
else f[i][j][tmp][]+=f[i-][k][r][];
f[i][j][tmp][]+=f[i-][k][r][];
}
}
int calc(int n){
int ans=,t=n,len=,r=,tmp;
bool flag=;
memset(a,,sizeof(a));
while (t) a[++len]=t%,t/=;
for (int i=len;i;i--){
for (int j=;j<a[i];j++){
tmp=((-(r+j*power[i]))%+)%;
for (int k=;k<=;k++) ans+=f[i-][k][tmp][];
if (!flag){
if (a[i+]==){if (j==) for (int k=;k<=;k++) ans+=f[i-][k][tmp][];}
if (j==) ans+=f[i-][][tmp][];
}
else for (int k=;k<=;k++) ans+=f[i-][k][tmp][];
}
r+=a[i]*power[i],r%=;
if (a[i+]==&&a[i]==) flag=;
}
return ans;
}
int main(){
init();
while (~scanf("%d",&n)) printf("%d\n",calc(n+));
return ;
}

hdu3652B-number的更多相关文章

  1. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  2. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  3. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  6. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  9. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  10. [LeetCode] Number of Segments in a String 字符串中的分段数量

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

随机推荐

  1. java的任务监听器监听任务

    Java自带的java.util.Timer类,这个类允许你调度一个java.util.TimerTask任务. 使用这种方式可以让你的程序按照某一个频度执行,但不能在指定时间运行.一般用的较少 监听 ...

  2. 微信公众平台--网页授权获取用户基本信息(snsapi_userinfo方式)

    关于snsapi_userinfo网页授权的说明 以snsapi_userinfo为scope发起的网页授权,是用来获取用户的基本信息的.但这种授权需要用户手动同意,并且由于用户同意过,所以无须关注, ...

  3. The app references non-public selectors in Payload

    上周上传app到appstore在validation完后有警告提示"The app references non-public selectors in Payload/wacao.app ...

  4. System.in与System.out(标准输入与标准输出)详解

    package test; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; p ...

  5. JBoss 系列十一:JBoss Cluster Framework Demo 介绍

    内容概要 JBoss Cluster Framework Demo包括JGruops.JBossCache.Infinispan,我们在随后的系列中会使用和运行这些示例来说明JGroups.JBoss ...

  6. springmvc 例

    1.结构 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaXRscWk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCM ...

  7. iOS开发--通过MultipeerConnectivity完成蓝牙通讯

    iOS开发–通过MultipeerConnectivity完成蓝牙通讯 iOS蓝牙通讯的三种方式: GameKit.framework:iOS7之前的蓝牙通讯框架,从iOS7开始过期,但是目前已经被淘 ...

  8. (转载)Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记

    Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记 Linux下配LMAP环境,花了我好几天的时间.之前没有配置过,网上的安装资料比较混乱,加上我用的版本问题,安装过程 ...

  9. Visual Studio 调试技巧 -- 为 Lambda 表达式设置中断

    如果我说 .NET 世界上最厉害的开发平台(语言),资深的同仁肯定不会往下看了,因为这将是一个无休止的争论,到头来搞不好还是人身攻击.然而,如果我说 Visual Studio 是世界上最友好最强大的 ...

  10. 设置Eclipse中文API提示信息

    准备工作:下载中文API到本机:http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish/1.6.0/html_ ...