Educational Codeforces Round 8 B 找规律
1 second
256 megabytes
standard input
standard output
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.
You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.
A substring of a string is a nonempty sequence of consecutive characters.
For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.
Print integer a — the number of substrings of the string s that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
124
4
04
3
5810438174
9 题意:给你一个串 询问子串中可以除尽4的个数 子串允许有前导‘0’ 题解:1.首先对于单个字符 ‘0’ ‘4’ ‘8’可以被除进
2.对于两个连续字符 组成的数exm=(s[i]-'0')+(s[i-1]-'0')*10必须除尽4
3.我们知道100能够整除4 所以只需要统计 以 (满足条件的两个连续字符)为后缀的子串的个数
求和
#include<bits/stdc++.h>
#define ll __int64
#define mod 1e9+7
#define PI acos(-1.0)
#define bug(x) printf("%%%%%%%%%%%%%",x);
#define inf 1e8
using namespace std;
#define ll long long
char s[];
map<int,int> mp;
ll ans;
int main()
{
scanf("%s",s);
ans=;
for(int i=;i<=;i+=)
mp[i]=;
int len=strlen(s);
for(int i=;i<len;i++)
{
if((s[i]-'')%==)
ans++;
int exm=(s[i]-'')+(s[i-]-'')*;
if(mp[exm])
{
ans=ans+i;
}
}
printf("%I64d\n",ans);
return ;
}
Educational Codeforces Round 8 B 找规律的更多相关文章
- Educational Codeforces Round 85 (Rated for Div. 2)
\(Educational\ Codeforces\ Round\ 85\ (Rated\ for\ Div.2)\) \(A. Level Statistics\) 每天都可能会有人玩游戏,同时一部 ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 5
616A - Comparing Two Long Integers 20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 59 (Rated for Div. 2) DE题解
Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 32
http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...
- Educational Codeforces Round 35 A. Nearest Minimums【预处理】
[题目链接]: Educational Codeforces Round 35 (Rated for Div. 2) A. Nearest Minimums time limit per test 2 ...
随机推荐
- 1503: [NOI2004]郁闷的出纳员
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 13723 Solved: 4989[Submit][Status][Discuss] Descripti ...
- 【CSS】css控制模块到顶层或底层
举例子,分别有div1和div2现要把div1控制在div2的顶层,可以这样做: } div.div2{} 两个要点:一.设置div的position为absolute,即绝对定位.二.z-index ...
- win7在某个盘或文件夹中出现右键只能新建文件夹的情况 (2012-12-28-bd 写的日志迁移
至于只能新建文件夹的情况如图: 解决方法是在运行中输入msconfig进入如图: 在系统设置选工具项在选中更改UAC设置点击启动如图: 如图: 直接把通知栏拉到最低确定即可(如果已经是最低了那就随便改 ...
- 迭代器Iterator与语法糖for-each
一.为什么需要迭代器 设计模式迭代器 迭代器作用于集合,是用来遍历集合元素的对象.迭代器迭代器不是Java独有的,大部分高级语言都提供了迭代器来遍历集合.实际上,迭代器是一种设计模式: 迭代器模式提供 ...
- Missian指南三:创建一个Missian服务器(使用spring)
在使用Missian时,spring是可选的,但是作者本人强烈推荐和Spring配合使用.Spring是一个伟大的项目,并且它不会对程序在运行时的效率带来任何损耗. Missian在服务器端依赖与Mi ...
- Python中的bytes
bytes_lst = [ ('创建bytes',), ('bytes可哈希',), ('编码与解码',), ('常见编码类型',), ('ord() 与 chr()',), ] 创建bytes &g ...
- oracle insert用法总结
总结下Oracle 中的Insert用法 1.标准Insert --单表单行插入 语法: INSERT INTO table [(column1,column2,...)] VALUE ...
- makefile学习(1)
GNU Make / Makefile 学习资料 GNU Make学习总结(一) GNU Make学习总结(二) 这篇学习总结,从一个简单的小例子开始,逐步加深,来讲解Makefile的用法. 最后用 ...
- BFS:HDU2597-Dating with girls(2) (分时间标记状态)
Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- SOA:面向服务编程——竹子整理
.net中如webservice,wcf,webapi,均可作为服务层,单独部署,而界面UI则部署在另一台服务器上,所有的业务逻辑均在服务层的业务层中进行. 这样一来,我们的UI其实就可以不限制语言, ...