CodeForces628-B.New Skateboard
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整除。因为100可以被4整除,所以100位以上的都可以,只要看个位和十位的数是否可以被4整除。
写这个题的时候傻了,只是算一下个位和十位就好了,然后把前面的位数加上就可以了,。
因为想一下,举个例子,xyzab,如果ab%4==0,那么xyzab可以组成多少个子串呢?那就是ab,zab,yzab,xyzab,就是a所在的位置啊,因为是从0开始的,所以位数+1,我可能是个傻子。。。
这样这道题就可以a了。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=*1e5+;
char a[N];
int main(){
while(~scanf("%s",a)){
ll len,cnt,ans;
len=strlen(a);
ans=;
for(int i=;i<len;i++){
if((a[i]-'')%==)ans++;
}
for(int i=;i<len-;i++){
cnt=(a[i]-'')*+(a[i+]-'');
if(cnt%==)ans+=i+;
}
cout<<ans<<endl;
}
return ;
}
CodeForces628-B.New Skateboard的更多相关文章
- Codeforces CF#628 Education 8 B. New Skateboard
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CF 628B New Skateboard --- 水题
CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...
- CodeForces 628B New Skateboard
New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 8 B. New Skateboard 暴力
B. New Skateboard 题目连接: http://www.codeforces.com/contest/628/problem/A Description Max wants to buy ...
- Codeforces 628 B.New Skateboard
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standar ...
- codeforces 628B B. New Skateboard (数论)
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces 628B New Skateboard 思维
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codefroces B. New Skateboard
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- New Skateboard
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new ...
随机推荐
- 免费SSL&付费SSL证书,该如何选择?
近年来Google.Apple.百度等公司不断推动 HTTPS 的普及,SSL 证书作为 HTTPS 安全协议的必备配置,自然也成为了网站.App 开发者最重要部署项目之一. 又拍云于 2016 年联 ...
- bzoj 3653 [湖南集训]谈笑风生
题目描述 设 T 为一棵有根树,我们做如下的定义: • 设 a 和 b 为 T 中的两个不同节点.如果 a 是 b 的祖先,那么称"a 比 b 不知道高明到哪里去了". • 设 a ...
- Chrome调试折腾记_(1)调试控制中心快捷键详解!!!
转载:http://blog.csdn.net/crper/article/details/48098625 大多浏览器的调试功能的启用快捷键都一致-按下F12;还是熟悉的味道; 或者直接 Ctrl ...
- KVM(一):KVM安装
KVM通俗的说就是一台服务器当多台用,详细介绍去百度和谷歌. 首先查看服务器是否支持虚拟化 [root@KVM ~]# grep -E '(vmx|svm)' /proc/cpuinfo --colo ...
- IT服务(运维)管理实施的几个要点--第二章 人员和组织架构
子曰"没有合适的人" 在流程化的管理模式下,最容易步入的一个误区是按流程设计一个"理想的"组织架构,然后对应于这个架构对人员进行评估.培养,甚至是更换.我见过很 ...
- 通过js中的useragrent来判断设备是pc端还是移动端,跳转不同的地址
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alc ...
- 当你的电脑出现stop: 0X0000007B
这几天可算是把我折腾惨了.先是linux系统无法进入图形化桌面,几经折腾,我把linux删除重装.怎知道,我在瘟都死下删除linux的分区,结果我的两个瘟都死分区也没了,哭了我去恢复数据,但是然并卵. ...
- Python并发实践_01_线程与进程初探
进程与线程 在多任务处理中,每一个任务都有自己的进程,一个任务会有很多子任务,这些在进程中开启线程来执行这些子任务.一般来说,可以将独立调度.分配的基本单元作为线程运行,而进程是资源拥有的基本单位. ...
- primer漏配问题解决
在对之前的ITS数据(454数据)做split时,发现有一些reads没有被匹配上,但是barcode能够完全匹配,虽然之后的primer在中间漏了一个碱基,导致后面的碱基全部误匹配,从而导致这条re ...
- <转>LOG日志级别
Level Description Example emerg Emergencies - system is unusable 紧急 - 系统无法使用 Child cannot open lock ...