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++,包括极大和极小 ...
随机推荐
- TCP之connect
1. connect函数: #include <sys/socket.h> int connect(int sockfd, const struct sockaddr *servaddr, ...
- 64_c1
CBFlib-0.9.5.15-3.fc26.i686.rpm 05-Feb-2017 21:55 427710 CBFlib-0.9.5.15-3.fc26.x86_64.rpm 05-Feb-20 ...
- C基础 一个可以改变linux的函数getch
引言 - getch简述 引用老的TC版本getch说明. (文章介绍点有点窄, 应用点都是一些恐龙游戏时代的开发细节) #include <conio.h> /* * 立即从客户端 ...
- jdk1.8在linux环境下的安装
转自博客:http://www.cnblogs.com/ShawnYuki/p/6816179.html
- MySQL中的内连接、外连接、交叉连接
内连接(INNER JOIN): 分为三种 等值连接.自然连接.不等连接 外连接(OUTER JOIN): 左外连接(LEFT OUTER JOIN或LEFT JOIN) 右 ...
- 在k8s 1.7.0上启用dashboard的注意事项
因为自k8s 1.6之后,有基于角色的安全性. 所以很多网上以前的教程就不能使用了. 结合以下三个文档,暂时实现了dashboard界面的推出. http://blog.csdn.net/jinzil ...
- slice切割数组arr=[[0,1],[2,3]]
for (var i = 0; i < 10; i++) { arr.push(i) } function arrSlice(arr, num) { var arr1 = []; for (va ...
- bzoj 1559 AC自动机 + dp
思路:直接在状态图上跑dp,最后枚举一下42种一下的.. 这个枚举有点恶心. #include<bits/stdc++.h> #define LL long long #define ll ...
- 如何在eclipse 中安装 spring IDE
1.先 确定 当前的eclipse 的版本:(步骤如下) 2.下载spring ide(请确定好ecplice 的版本号) http://spring.io/tools/sts/all 最后: 安装 ...
- Java中分拣存储的demo
//Letter.java package yzhou.map; /** * * @author 洋 * */ public class Letter { private String name; ...