Codefroces 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
个位十位分情况讨论
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
char a[];
int main()
{
scanf("%s",&a);
ll ans=;
int len=strlen(a);
int k=(int)a[]-;
if(k%==) ans++;
for(int i=;i<len;i++)
{
k=(int)a[i]-;
if(k%==) ans++;
int s=(int)a[i-]-;
if((s*+k)%==) ans+=i;
}
printf("%I64d\n",ans);
return ;
}
Codefroces B. New Skateboard的更多相关文章
- Codefroces 628B New Skateboard(数位+思维)
题目链接:http://codeforces.com/contest/628/problem/B 题目大意:给你一段数字串s(1?≤?|s|?≤?3·10^5),求该字符串有多少子串是4的倍数.解题思 ...
- 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 ...
- CodeForces628-B.New Skateboard
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 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 ...
随机推荐
- 1x1卷积核作用
1. 实现跨通道的交互和信息整合 对于某个卷积层,无论输入图像有多少个通道,输出图像通道数总是等于卷积核数量! 对多通道图像做1x1卷积,其实就是将输入图像于每个通道乘以卷积系数后加在一起,即相当于把 ...
- Python对象的循环引用问题
目录 Python对象循环引用 循环引用垃圾回收算法 容器对象 生成容器对象 追踪容器对象 结束追踪容器对象 分代容器对象链表 何时执行循环引用垃圾回收 循环引用的垃圾回收 循环引用中的终结器 pyt ...
- ssh 免交互式登陆
脚本: vim key.sh #!/bin/bash#make key\rm -f /root/.ssh/id_dsassh-keygen -t dsa -f /root/.ssh/id_dsa -P ...
- python在leecode刷题-第一题和第七题
class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] num ...
- Node实现简单的注册时后端的MVC模型架构
实现一个简单的注册界面后端MVC模型架构 第一步:在生成的express框架的app.js中添加一个路由,代码如下:var api = require('./routes/api'); app.use ...
- springboot框架笔记——springboot提供的自动配置
Springboot基本配置 spring MVC的定制配置需要我们的配置实现一个WebMvcConfigurer接口,如果实在spring环境下需要使用@EnableWebMVC注解,来开启对spr ...
- 【Codeforces Beta Round #45 D】Permutations
[题目链接]:http://codeforces.com/problemset/problem/48/D [题意] 给你n个数字; 然后让你确定,这n个数字是否能由若干个(1..x)的排列连在一起打乱 ...
- Opencv YAML和XML格式文件操作详解
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/47660943 本文参考Opencv 2 ...
- 洛谷 P1703 那个什么密码2
P1703 那个什么密码2 题目背景 https://www.luogu.org/problem/show?pid=1079 题目描述 与原题一模一样.具体不同请见输入格式 输入输出格式 输入格式: ...
- Android Volley 具体解释 Google公布的一套用于网络通信的工具库
下载地址:git clone https://android.googlesource.com/platform/frameworks/volley 或 : https://github.com/mc ...