题目链接:http://codeforces.com/contest/628/problem/B

题目大意:
给你一段数字串s(1?≤?|s|?≤?3·10^5),求该字符串有多少子串是4的倍数。
解题思路:
很容易可以想到,如果一个两位数可以被4整除,那么在它左边加任何数字都能被4整除,如24能被4整除,那么124,1324也可以。因为第3位就是百位,
只要是100的倍数肯定也是4的倍数。所以只用考虑前两位即可。

代码:

 #include<bits/stdc++.h>
#define lc(a) (a<<1)
#define rc(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name) freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define _for(i,start,end) for(int i=start;i<=end;i++)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=5e6+;
const int INF=0x3f3f3f3f;
const double eps=1e-; int main(){
FAST_IO;
string str;
cin>>str;
int sze=str.size();
LL ans=;
for(int i=sze-;i>=;i--){
int num=str[i]-'';
if(num%==)
ans++;
if(i>){
int t=num+(str[i-]-'')*;
if(t%==)
ans+=i; //若s[i]*10+s[i-1] 能被4整除那么数字左边无论加什么都会被4整除
}
}
cout<<ans<<endl;
return ;
}

Codefroces 628B New Skateboard(数位+思维)的更多相关文章

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

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

  2. CodeForces 628B New Skateboard 思维

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

  3. CodeForces 628B New Skateboard

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

  4. Codefroces 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 8

    开始填坑_(:з」∠)_ 628A - Tennis Tournament    20171124 小学数学题,\((x,y)=((n-1)\cdot(2b+1),np)\) #include< ...

  6. Codeforces 914 C 数位DP+暴力打表+思维

    题意 给出一个二进制数\(n\),每次操作可以将一个整数\(x\)简化为\(x\)的二进制表示中\(1\)的个数,如果一个数简化为\(1\)所需的最小次数为\(k\),将这个数叫做特殊的数, 问从\( ...

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

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

  8. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

  9. 剑指 Offer 43. 1~n 整数中 1 出现的次数 + 数位模拟 + 思维

    剑指 Offer 43. 1-n 整数中 1 出现的次数 Offer_43 题目描述 题解分析 java代码 package com.walegarrett.offer; /** * @Author ...

随机推荐

  1. 1.Qt简介

    附件列表 1.Qt简介.png

  2. R语言:R2OpenBUGS

    R语言:R2OpenBUGS 用这个包调用BUGS model,分别用表格和图形概述inference和convergence,保存估计的结果 as.bugs.array 转换成bugs object ...

  3. P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚

    P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚 你有一段区间需要被覆盖(长度 <= 86,399) 现有 \(n \leq 10000\) 段小线段, 每段可 ...

  4. IOS计算文字高度

    1.计算文字长度 NSString* str = @"你好"; .f; NSStringDrawingOptions options = NSStringDrawingUsesLi ...

  5. windows下静态编译pthread

    1. Building the library as a statically linkable library-------------------------------------------- ...

  6. c# lock的误解

    一直以为lock 一个实例就可以了,没想到实例的类型还是有区别的 static object lockObjStatic = new object(); object lockObj = new ob ...

  7. SSM简单整合教程&测试事务

    自打来了博客园就一直在看帖,学到了很多知识,打算开始记录的学习到的知识点 今天我来写个整合SpringMVC4 spring4 mybatis3&测试spring事务的教程,如果有误之处,还请 ...

  8. soj2012.King(有向图+蛋疼得一逼)

    Description There are n children in a country marked by integers from 1 to n. They often fight with ...

  9. 你对position的了解到底有多少?

    此文根据Steven Bradley的<How Well Do You Understand CSS Positioning?>所译,整个译文带有我自己的理解与思想,如果译得不好或不对之处 ...

  10. 阿里云的OCS缓存机制

    OCS简介 OCS( Open Cache Service)为分布式高速缓存服务,主要实现热点数据的快速响应: OCS支持Key/Value的数据结构,兼容memcachebinary protoco ...