B. New Skateboard
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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.

Examples
input
124
output
4
input
04
output
3
input
5810438174
output
9

题意:给你一串数,让你找出其中有几个子串是4的倍数(包括总串)。

思路:暴搜必定超时O(n^2),我们可以分类讨论。先考虑一位数,当满足4的倍数时c++;然后是两位数,满足条件+1,这时就要考虑当两位数满足4的倍数时,前面不管再加多少位,都是4的倍数(100、1000、10000...都能被4整除),那么我们就可以把两位数前面的数字(i个)依次加上,他们分别是以两位数为尾的三位数、四位数、五位数...因此c+i+1。O(n+n)。

#include<stdio.h>
#include<string.h> int main()
{
long long c,i;
char s[];
scanf("%s",s);
c=;
for(i=;i<strlen(s);i++){
if((s[i]-'')%==) c++;
}
for(i=;i<strlen(s)-;i++){
if(((s[i]-'')*+(s[i+]-''))%==) c+=i+;
}
printf("%lld\n",c);
return ;
}

CodeForces 628B New Skateboard 思维的更多相关文章

  1. CodeForces 628B New Skateboard

    New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. CF 628B New Skateboard --- 水题

    CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...

  3. Codefroces 628B New Skateboard(数位+思维)

    题目链接:http://codeforces.com/contest/628/problem/B 题目大意:给你一段数字串s(1?≤?|s|?≤?3·10^5),求该字符串有多少子串是4的倍数.解题思 ...

  4. codeforces 628B B. New Skateboard (数论)

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  6. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  7. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  8. Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】

    B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...

  9. Codeforces 675C Money Transfers 思维题

    原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...

随机推荐

  1. oracle sqlplus 常用操作

    命令 含义 / 运行 SQL 缓冲区 ? [关键词] 对关键词提供 SQL 帮助 @[@] [文件名] [参数列表] 通过指定的参数,运行指定的命令文件 ACC[EPT] 变量 [DEF[AULT] ...

  2. Scrapy爬虫入门系列2 示例教程

    本来想爬下http://www.alexa.com/topsites/countries/CN 总排名的,但是收费了 只爬了50条数据: response.xpath('//div[@class=&q ...

  3. Nmap扫描教程之基础扫描具体解释

    Nmap扫描教程之基础扫描具体解释 Nmap扫描基础扫描 当用户对Nmap工具了解后,就可以使用该工具实施扫描.通过上一章的介绍,用户可知Nmap工具能够分别对主机.port.版本号.操作系统等实施扫 ...

  4. PHP中的面向对象 中的类(class)

    2.11 上午讲的是面向对象中的类(class),一个非常抽象的概念, 类里面成员的定义有 public$abc; private$abc(私有变量): protect $abc(受保护的变量): 下 ...

  5. macos下查看用户组,以及修改文件权限

    查看当前用户所属组 groups 查看指定用户所属组 groups username 更改权限 将单个文件更改为777权限 chmod 777 aaa.txt 更改文件夹所属组 sudo chown ...

  6. TTimer很特殊

    TTimer = class(TComponent) private FInterval: Cardinal; FWindowHandle: HWND; FOnTimer: TNotifyEvent; ...

  7. 6.JS输出

    JavaScript 通常用于操作 HTML 元素. ① document.getElementById(id),可以访问某个 HTML 元素 请使用 "id" 属性来标识 HTM ...

  8. Hibernate总结(转)

    原文:http://blog.csdn.net/yuebinghaoyuan/article/details/7300599 那我们看一下hibernate中整体的内容: 我们一一介绍其中的内容. H ...

  9. 基于springboot的Dubbo的常规总结

    1.引入jar包: <!-- Spring Boot Dubbo 依赖 --> <dependency> <groupId>com.alibaba.spring.b ...

  10. HDU1873 看病要排队 —— 优先队列(STL)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873 题解: 题目已经说出了解题方法:优先队列.但是之前没有学过优先队列,而且这题还是在现场赛做的.由 ...