1599 - Multiple

时间限制:2秒 内存限制:64兆

461 次提交 111 次通过

题目描述

Rocket323 loves math very much. One day, Rocket323 got a number string. He could choose some consecutive digits from the string to form a number. Rocket323 loves 64 very much, so he wanted to know how many ways can he choose from the string so the number he got multiples of 64 ?

A number cannot have leading zeros. For example, 0, 64, 6464, 128 are numbers which multiple of 64 , but 12, 064, 00, 1234 are not.

输入

Multiple cases, in each test cases there is only one line consist a number string.

Length of the string is less than 3 * 10^5 .

Huge Input , scanf is recommended.

输出

Print the number of ways Rocket323 can choose some consecutive digits to form a number which multiples of 64.

样例输入

64064

样例输出

5

提示

There are five substrings which multiples of 64.

[64]064

640[64]

64[0]64

[64064]

[640]64

来源

Problem Setter : Yang Xiao

思路:

根据同余定理,每次枚举到一个数,都把前面的存在的余数乘以10加上这个数再对64取余,就产生新的余数,最后统计余数是0的个数有多少

#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h> using namespace std;
char a[300005];
long long int dp[2][65];
long long int tag[65];
long long int ans;
long long int res;
int now;
int main()
{
while(scanf("%s",a)!=EOF)
{
ans=0;res=0;
int len=strlen(a);
memset(dp,0,sizeof(dp));
now=0;
for(int i=0;i<len;i++)
{
for(int j=63;j>=0;j--)
dp[now^1][j]=0;
for(int j=63;j>=0;j--)
{
int num=(j*10+a[i]-'0'+64)%64;
dp[now^1][num]+=dp[now][j]; }
if(a[i]!='0')
dp[now^1][a[i]-'0']++;
else
ans++;
res+=dp[now^1][0];
now^=1; }
printf("%lld\n",res+ans);
}
return 0;
}

HUST 1599 - Multiple(动态规划)的更多相关文章

  1. HUST - 1599 Multiple

    input 长度不大于3*10e5的数字串 output 不含前导0的能整除64的字串的个数(0算一个,064不算) 一般数组中找能整除一个数的字串都是用取余来做的 用一个a[64]来存下从1-i位累 ...

  2. POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心)-动态规划做法

    POJ 3659 Cell Phone Network / HUST 1036 Cell Phone Network(最小支配集,树型动态规划,贪心) Description Farmer John ...

  3. ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)

    Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...

  4. [leetcode] 题型整理之动态规划

    动态规划属于技巧性比较强的题目,如果看到过原题的话,对解题很有帮助 55. Jump Game Given an array of non-negative integers, you are ini ...

  5. [ACM_动态规划] 轮廓线动态规划——铺放骨牌(状态压缩1)

    Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, af ...

  6. hdu 1087 动态规划之最长上升子序列

    http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online C ...

  7. POJ 1426 Find The Multiple --- BFS || DFS

    POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...

  8. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  9. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

随机推荐

  1. error LNK2038: 检测到“_MSC_VER”的不匹配项: 值“1600”不匹配值“1800”

    _MSC_VER 定义编译器的版本.下面是一些编译器版本的_MSC_VER值:MS VC++ 10.0 _MSC_VER = 1600MS VC++ 9.0 _MSC_VER = 1500MS VC+ ...

  2. zabbix添加对tomcat线程池的监控

    在zabbix模板中添加以下监控项: 可以参考文档:http://www.fblinux.com/?p=616

  3. Data Guard启动实时日志应用

    1. REDO数据实时应用 启动实时应用的优势在于,REDO数据不需要等待归档完成,接收到即可被应用,这样执行角色切换时,操作能够执行得更快,因为日志是被即时应用的. 要启动实时应用也简单,前提是St ...

  4. Splash 简介与安装

    Splash 说白了就是一个轻量级的浏览器,利用它,我们同样可以实现跟其他浏览器一样的操作,我们使用 Docker 来安装 Splash: [root@localhost ~]# docker run ...

  5. [C/E] 等差数列求和

    题目:要求给定一个整数 N,求从 0 到 N 之间所有整数相加之和. 解1:使用 for 循环依次递加. #include <stdio.h> int main(void){ int x; ...

  6. Linux下用C获取当前时间

    Linux下用C获取当前时间,具体如下: 代码(可以把clock_gettime换成time(NULL)) ? 1 2 3 4 5 6 7 8 9 10 void getNowTime() {  ti ...

  7. javascript的初步认识

    把握自己,就是时时拥有一颗清澈的心,拥有一片明朗的情怀.嘿嘿,我们在2014-2015的跨度里,我们休息了的四天,今天又回到了学习的阶段,敲起来键盘突然有点陌生,想一想时间真的好快,在这里我们已经是跨 ...

  8. javaWeb项目重命名的问题

    tomcat项目名称修改 步骤: 1.对工程重命名(选择工程,右键Refactor->Rename)      2.修改Web路径(选择工程,右键Properties->MyEclipse ...

  9. Git学习之Git 暂存区

    ============================= 修改文件后是否可以直接提交 ============================ (1) 向文件中追加一行内容  $ echo &quo ...

  10. java基础---->使用Itext生成数据库文档

    这里简单的介绍一下使用Itext生成数据库表的文档.于是我们领教了世界是何等凶顽,同时又得知世界也可以变得温存和美好. 生成数据库的文档 一.maven项目需要引入的jar依赖 <depende ...