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 暴力的更多相关文章

  1. Educational Codeforces Round 8 A. Tennis Tournament 暴力

    A. Tennis Tournament 题目连接: http://www.codeforces.com/contest/628/problem/A Description A tennis tour ...

  2. Educational Codeforces Round 1 A. Tricky Sum 暴力

    A. Tricky Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem ...

  3. Educational Codeforces Round 8 B. New Skateboard

    题目链接:http://codeforces.com/problemset/problem/628/B 解题思路: 一个数最后两位数能被4整除那么这个数就能被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 ...

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

  6. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  7. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  8. Educational Codeforces Round 59 (Rated for Div. 2) DE题解

    Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...

  9. Educational Codeforces Round 32

    http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...

随机推荐

  1. 某labs上传writeup-上传漏洞总结

    github:https://github.com/d0ef/upload-labs 第一题:通过JS判断的直接抓包改了就ok. 第二题:只要Content-Type信息为图片的就可以 第三题:通过上 ...

  2. Linux内核的架构

    GNU/Linux操作系统架构 备注:IPC进程间通.IPC(Inter-Process Communication)是共享"命名管道"的资源,它是为了让进程间通信而开放的命名管道 ...

  3. python基础===pendulum '''Python datetimes made easy.'''

    https://pypi.python.org/pypi/pendulum Pendulum的一大优势是内嵌式取代Python的datetime类,可以轻易地将它整合进已有代码,并且只在需要的时候才进 ...

  4. socket.io入门整理

    我自己在用socket.io开发,对官方网站上的文档,进行简单的整理,然后自己写了一个简单的聊天程序. 最最开始 先安装socket.io: 1 npm install socket.io 利用Nod ...

  5. Python爬虫数据处理

    一.首先理解下面几个函数 设置变量 length()函数 char_length() replace() 函数 max() 函数1.1.设置变量 set @变量名=值 set @address='中国 ...

  6. jdbc连接远程数据库进行操作

    链接远程数据库的时候,要把获得链接的url进行修改 1 package com.test; import java.sql.Connection; import java.sql.DriverMana ...

  7. linux命令(33):tail命令

    1.命令格式; tail[必要参数][选择参数][文件] 2.命令功能: 用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理.常用查看日志文件. 3.命令参数: -f 循环读取 -q 不显示 ...

  8. hdu 2147(巴什博弈+NP图)

    kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)Total ...

  9. Integer to Roman——相当于查表法

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  10. Python安装scikit-learn包

    我先是按照网上说的下载了个setuptools,然后直接用这个工具去安装,可是安装scikit-learn包的时候确老是有错误,也不知道错误是啥,所以就不用setuptools来安装了. 我直接下载了 ...