Codefroces 628B New Skateboard(数位+思维)
题目链接: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(数位+思维)的更多相关文章
- CF 628B New Skateboard --- 水题
CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...
- CodeForces 628B New Skateboard 思维
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CodeForces 628B New Skateboard
New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codefroces 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
开始填坑_(:з」∠)_ 628A - Tennis Tournament 20171124 小学数学题,\((x,y)=((n-1)\cdot(2b+1),np)\) #include< ...
- Codeforces 914 C 数位DP+暴力打表+思维
题意 给出一个二进制数\(n\),每次操作可以将一个整数\(x\)简化为\(x\)的二进制表示中\(1\)的个数,如果一个数简化为\(1\)所需的最小次数为\(k\),将这个数叫做特殊的数, 问从\( ...
- codeforces 628B B. New Skateboard (数论)
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces D. Little Elephant and Interval(思维找规律数位dp)
题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...
- 剑指 Offer 43. 1~n 整数中 1 出现的次数 + 数位模拟 + 思维
剑指 Offer 43. 1-n 整数中 1 出现的次数 Offer_43 题目描述 题解分析 java代码 package com.walegarrett.offer; /** * @Author ...
随机推荐
- Spring MVC+Spring+Mybatis+MySQL(IDEA)入门框架搭建
目录 Spring MVC+Spring+Mybatis+MySQL(IDEA)入门框架搭建 0.项目准备 1.数据持久层Mybatis+MySQL 1.1 MySQL数据准备 1.2 Mybatis ...
- 解题:POI 2013 Triumphal arch
题面 二分答案,问题就转化为了一个可行性问题,因为我们不知道国王会往哪里走,所以我们要在所有他可能走到的点建造,考虑用树形DP解决(这个DP还是比较好写的,你看我这个不会DP的人都能写出来=.=) 定 ...
- 如何设置C++崩溃时生成Dump文件
Dump 文件是进程的内存镜像 , 可以把程序的执行状态通过调试器保存到dump文件中 ; Dump 文件是用来给驱动程序编写人员调试驱动程序用的 , 这种文件必须用专用工具软件打开 , 比如使用 W ...
- 「转」图像算法---白平衡AWB
本文大体讲解了白平衡的算法流程,适用于想了解和学习白平衡原理的筒子们. 一般情况下要实现AWB算法需要专业的图像和算法基础,本文力图通过多图的方式,深入浅出,降低初学者理解上的门槛,让大家都理解到白平 ...
- Spyder使用IPython Console弹出绘图窗口的设置方法
http://www.datastudy.cc/article/3cfc3aff3b2c5948b938456e00376276 在使用Spyder的过程中,因为它的绘图,默认是绘图在IPython窗 ...
- HDU 3271 数位dp+二分
SNIBB Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- P1993 小K的农场 && 差分约束
首先第一篇讨论的是差分约束系统解的存在 差分约束系统是有 \(n\) 个变量及 \(m\) 个(如 \(x_{i} - x_{j} \leq a_{k}\) )关系组成的系统 差分约束解的求解可以转化 ...
- Hadoop生态圈-Hive的自定义函数之UDAF(User-Defined Aggregation Function)
Hadoop生态圈-Hive的自定义函数之UDAF(User-Defined Aggregation Function) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.
- 科学计算三维可视化---Mlab基础(改变物体的外观颜色)
import numpy as np from mayavi import mlab #建立数据 x,y = np.mgrid[-::200j,-::200j] z = *np.sin(x*y)/(x ...
- [LeetCode] 398. Random Pick Index ☆☆☆
Given an array of integers with possible duplicates, randomly output the index of a given target num ...