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. C# FileSystemWatcher 在监控文件夹和文件时的用法

    概述 最近学习FileSystemWatcher的用法,它主要是监控一个文件夹,当文件夹内的文件要是有更改就要记录下来,我就整理下我对FileSystemWatcher 的理解和用法. FileSys ...

  2. Java Comparable和Comparator

    Java中在进行数据排序时,Comparable和Comparator不可缺少会遇得到.普通的String.Integer等类型,已经实现了Comparable接口,而有些时候,我们须要对一些其它不存 ...

  3. Ubuntu 16.04服务器 配置

    1. 修改用户名称:切换到root打开如下两个配置文件 sudo vim /etc/passwd 把我想改的"xxx"这个用户名改为"way"了,保存并退出 s ...

  4. Python 统计代码量

    #统计代码量,显示离10W行代码还有多远 #递归搜索各个文件夹 #显示各个类型的源文件和源代码数量 #显示总行数与百分比 import os import easygui as g #查找文件 def ...

  5. 【GIS】Cesium GLTF

    cd D:\GISSoft\3DsMax2017\COLLADA2GLTF-v2.1.4-windows-Release-x64 COLLADA2GLTF-bin.exe -f tree05.DAE ...

  6. 升级nodejs至最新

    网上找出了很多升级nodejs版本的方法,都不太好用,直至发现这个: 在命令行窗口中执行:where node: 然后在nodejs官网中下载最新版本,将刚才目录下node.exe替换掉: 最后执行: ...

  7. c++学习笔记—c++对txt文件的读取与写入

    一.文件的输入输出 头文件fstream定义了三个类型支持文件IO:ifstream从给定文件读取数据.ofstream向一个给定文件写入数据.fstream读写给定数据.这些类型与cin和cout的 ...

  8. spring applicationContext.xml 配置文件 详解

      <?xml version="1.0" encoding="UTF-8"?>   <beans xmlns="http://ww ...

  9. 用layer插件实现tp3.2的分页

    主要需要用到  /layer/layer.js  这个, 现在一个tp前端视图/article/index.html <!DOCTYPE html> <html lang=" ...

  10. Webpack 备忘录

    Webpack 属于在项目中配置一次就很少改动的那种工具,但这样就导致新项目再配置 Webpack 时会有些生疏,所以将 Webpack 核心概念及常用配置记录如下. 1)核心概念 Webpack 4 ...