Educational Codeforces Round 8 B. New Skateboard 暴力
B. New Skateboard
题目连接:
http://www.codeforces.com/contest/628/problem/A
Description
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.
Input
The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.
Output
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.
Sample Input
124
Sample Output
4
Hint
题意
给你一个只含有数字的串,然后问你有多少个子串是4的倍数,可以有前导0
题解:
4的倍数的话,当且仅当这个数的个位和十位能被4整除
那么我们扫一遍统计一下就好了,如果这个个位和十位能被4整除,那么他的贡献就是他是整个字符串的第几位
因为他和他的前缀组合起来肯定也是4的倍数
代码
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
long long ans = 0;
for(int i=0;i<s.size();i++)
if((s[i]-'0')%4==0)
ans++;
for(int i=1;i<s.size();i++)
if(((s[i-1]-'0')*10+(s[i]-'0'))%4==0)
ans+=1ll*i;
cout<<ans<<endl;
}
Educational Codeforces Round 8 B. New Skateboard 暴力的更多相关文章
- Educational Codeforces Round 8 A. Tennis Tournament 暴力
A. Tennis Tournament 题目连接: http://www.codeforces.com/contest/628/problem/A Description A tennis tour ...
- Educational Codeforces Round 1 A. Tricky Sum 暴力
A. Tricky Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem ...
- Educational Codeforces Round 8 B. New Skateboard
题目链接:http://codeforces.com/problemset/problem/628/B 解题思路: 一个数最后两位数能被4整除那么这个数就能被4整除,而且题目还是连续的子序列,这就很简 ...
- Educational Codeforces Round 19 E. Array Queries(暴力)(DP)
传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #i ...
- Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- 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 59 (Rated for Div. 2) DE题解
Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...
- Educational Codeforces Round 32
http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...
随机推荐
- kernel cmdline
從 lk 傳送到 kerel 的 cmdline 會放在開機後的 adb /proc/cmdline 開到 android 後,又會被讀出來 /system/core/init/util.cpp 27 ...
- Win10打开照片提示“无效的注册表值”解决方法
1.点开开始菜单,右键单击,选择“以管理员运行”[键盘win键+R]输入PowerShell. 2.输入Get-AppxPackage *photo* | Remove-AppxPackage后回车. ...
- overflow属性在IE6下面失去效果
自然状态下 overflow的属性设置,本来是超过了一定的长度时会自动产生滚动条,但是在ie6下面失效了. 例如:原来的代码: .code{overflow-x:auto;margin:5px aut ...
- MySQL数据库分表分区(一)(转)
面对当今大数据存储,设想当mysql中一个表的总记录超过1000W,会出现性能的大幅度下降吗? 答案是肯定的,一个表的总记录超过1000W,在操作系统层面检索也是效率非常低的 解决方案: 目前针对 ...
- Leetcode 之Longest Common Prefix(34)
这题实现起来还是挺麻烦的,就偷懒使用下库函数strtod().第二个参数表示字符中不是数字的地方,如果后面是空格,则认为其仍是数字,否则不是. bool isNumber(char *s) { cha ...
- redis 的优化
1.pipeling “请求-响应”模式的服务器在处理完一个请求后就开始处理下一个请求,不管客户端是否读取到前一个请求的响应结果.这让客户端不需要发一个请求等一个响应的串行,可以一次发送多个请求,再最 ...
- (转载)IntelliJ IDEA 自动导入包 快捷方式
原文地址:IntelliJ IDEA 自动导入包 快捷方式 idea可以自动优化导入包,但是有多个同名的类调用不同的包,必须自己手动Alt+Enter设置 设置idea导入包 勾选标注 1 选项,In ...
- ORACLE中函数MONTHS_BETWEEN的使用
格式:MONTHS_BETWEEN(DATE1,DATE2) MONTHS_BETWEEN函数返回两个日期之间的月份数. SQL> ', 'yyyymmdd')) as months from ...
- hdu 1495(BFS)
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Set Matrix Zeroes——常数空间内完成
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Did yo ...