HUST 1599 Multiple

Multiple

Time Limit: 2
Sec  Memory Limit: 64
MB
Submissions: 197  Solved: 35

Description


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. Rocket323loves 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.

Input

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.

Output

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

Sample Input

64064

Sample Output

5

HINT

There are five substrings which multiples of
64.
[64]064
640[64]
64[0]64
[64064]
[640]64

题目大意是:给出一个串,求有多少个子串(无前导0)能被64整除。

分析:单独的一个子串“0”肯定是的,再暴搜子串字符个数为2、3、4、5、6的能被64整除的,1000000%64==0。

所以字符个数为6的可以整除64的可以特殊判断一下:

高位为0,那么他本身不符合(有前导0),但在它前面加任意一个不为0的数都能整除64。所以加上他前面不为0数字个数。

高位不为0,那么再加上它本身这一种。


 1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 using namespace std;
5
6 typedef __int64 LL;
7 const int maxn=300005;
8 char text[maxn];
9 int d[maxn];
10
11 void solve()
12 {
13 int i,len=strlen(text);
14 if(text[0]==‘0‘) d[0]=1;
15 else d[0]=0;
16 for(i=1;i<len;i++)
17 {
18 if(text[i]==‘0‘) d[i]=d[i-1]+1;
19 else d[i]=d[i-1];
20 }
21 LL ans=d[len-1];
22 for(i=len-1;i>=1;i--)
23 if(text[i-1]!=‘0‘ && ((text[i-1]-‘0‘)*10+text[i]-‘0‘)%64==0) ans++;
24 for(i=len-1;i>=2;i--)
25 if(text[i-2]!=‘0‘ && ((text[i-2]-‘0‘)*100+(text[i-1]-‘0‘)*10+text[i]-‘0‘)%64==0) ans++;
26 for(i=len-1;i>=3;i--)
27 if(text[i-3]!=‘0‘ && ((text[i-3]-‘0‘)*1000+(text[i-2]-‘0‘)*100+(text[i-1]-‘0‘)*10+text[i]-‘0‘)%64==0) ans++;
28 for(i=len-1;i>=4;i--)
29 if(text[i-4]!=‘0‘ && ((text[i-4]-‘0‘)*10000+(text[i-3]-‘0‘)*1000+(text[i-2]-‘0‘)*100+(text[i-1]-‘0‘)*10+text[i]-‘0‘)%64==0) ans++;
30 for(i=len-1;i>=5;i--)
31 {
32 if(((text[i-5]-‘0‘)*100000+(text[i-4]-‘0‘)*10000+(text[i-3]-‘0‘)*1000+(text[i-2]-‘0‘)*100+(text[i-1]-‘0‘)*10+text[i]-‘0‘)%64==0)
33 {
34 if(text[i-5]!=‘0‘) ans++;
35 if(i-5>0) ans+=i-5-d[i-5-1];
36 }
37 }
38 printf("%I64d\n",ans);
39 }
40 int main()
41 {
42 while(gets(text))
43 {
44 solve();
45 }
46 return 0;
47 }

HUST 1599 Multiple,布布扣,bubuko.com

时间: 2024-12-17 04:17:50

HUST 1599 Multiple的相关文章

hust 1385 islands 并查集+搜索

islands Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/problem/show/1385 Description Deep in the Carribean, there is an island even stranger than the Monkey Island, dwelled by Horatio Torquemada Marley. Not only it has a rectangu

hust 1546 &amp;&amp; hdu 3911 Black And White

题目描述 There are a bunch of stones on the beach; Stone color is white or black. Little Sheep has a magic brush, she can change the color of a continuous stone, black to white, white to black. Little Sheep like black very much, so she want to know the l

hust 1347 - Reverse Number

题目描述 Given a non-negative integer sequence A with length N, you can exchange two adjacent numbers each time. After K exchanging operations, what’s the minimum reverse number the sequence can achieve? The reverse number of a sequence is the number of

hust 1062 Divisibility

题目描述 On the planet Zoop, numbers are represented in base 62, using the digits 0, 1, . . . , 9, A, B, . . . , Z, a, b, . . . , z where A (base 62) = 10 (base 10) B (base 62) = 11 (base 10) . . . z (base 62) = 61 (base 10). Given the digit representati

hust 1540 Yy’s celebration

题目描述 It's Yy's birthday, and his friends decided to buy him a copy of XianJianQiXiaZhuan V.Since some of friends have more money available than others, nobody has to pay more than he can afford. Every contribution will be a multiple of 1 cent,i.e.,no

HUST 1588 辗转数对

1588 - 辗转数对 时间限制:1秒 内存限制:128兆 155 次提交 27 次通过 题目描述 假设当前有一个数对(a, b),我们可以通过一步将这个数对变为一个新数对(a + b, b)或者是(a, a + b).初始的数对为(1, 1),你的任务是找到一个数字k,即通过最少的步数使得这个数对中至少一个数字等于n. 输入 输入包括多组数据,每组数据包括一行,每行有一个整数n. 输出 每组数据输出一行,每行一个整数n. 样例输入 5 3 样例输出 3 2 提示 第一个样例的方法是 (1,1)

HUST 1698 - 电影院 组合数学 + 分类思想

http://acm.hust.edu.cn/problem/show/1698 题目就是要把一个数n分成4段,其中中间两段一定要是奇数. 问有多少种情况. 分类, 奇数 + 奇数 + 奇数 + 奇数 奇数 + 奇数 + 奇数 + 偶数 偶数 + 奇数 + 奇数 + 奇数 偶数 + 奇数 + 奇数 + 偶数 然后奇数表达成 2 * a - 1这个样子,就能列出方程. 然后就是类似于解a1 + a2 + a3 + a4 = x的问题了. #include <cstdio> #include &l

Error: Can&#39;t place multiple pins assigned to pin location……解决办法

转载:http://blog.sina.com.cn/s/blog_6f0eeb3301014pi7.html 今天用DE0做VGA实验,在分配管脚后全编译出现下面这样的错误: Error: Can't place multiple pins assigned to pin location Pin_K22 (IOPAD_X41_Y19_N14) Info: Pin B[0] is assigned to pin location Pin_K22 (IOPAD_X41_Y19_N14) Info

HDOJ 4474 Yet Another Multiple Problem

BFS..... Yet Another Multiple Problem Time Limit: 40000/20000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3307    Accepted Submission(s): 806 Problem Description There are tons of problems about integer multiple