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 ...
随机推荐
- bzoj3473: 字符串 && bzoj3277串
3473: 字符串 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 121 Solved: 53[Submit][Status][Discuss] D ...
- 【纪中集训2019.3.13】fft
题意: 描述 一共有\(n+m\)道题,其中\(n\)道答案是\(A\),\(m\)道答案是\(B\): 你事先知道\(n和m\),问在最优情况下的期望答错次数,对\(998244353\)取模: 范 ...
- .net 控件开发常见的特性总结
http://blog.csdn.net/aofengdaxia/article/details/5924364 在.net开发中常常需要使用一些[]里面的特性描述,我发现对常用的几个知道大概的意思, ...
- 线性判别分析 LDA
点到判决面的距离 点\(x_0\)到决策面\(g(x)= w^Tx+w_0\)的距离:\(r={g(x)\over \|w\|}\) 广义线性判别函数 因任何非线性函数都可以通过级数展开转化为多项式函 ...
- 从 php 源码看 php 中的对象
从一个简单的例子说起: class Person { public $name; public $age; public function __construct($name, $age) { $th ...
- SSO基于cas的登录
概念介绍 1.定义 CAS ( CentralAuthentication Service ) 是 Yale 大学发起的一个企业级的.开源的项目,旨在为 Web 应用系统提供一种可靠的单点登录解决方法 ...
- mysql查改
1 MySQL UNION 操作符语法格式: SELECT expression1, expression2, ... expression_n FROM tables [WHERE conditio ...
- Hadoop生态圈-Hive快速入门篇之HQL的基础语法
Hadoop生态圈-Hive快速入门篇之HQL的基础语法 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客的重点是介绍Hive中常见的数据类型,DDL数据定义,DML数据操作 ...
- 51nod 1534 棋子游戏
1534 棋子游戏 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 http://www.51nod.com/onlineJudg ...
- 随机森林入门攻略(内含R、Python代码)
随机森林入门攻略(内含R.Python代码) 简介 近年来,随机森林模型在界内的关注度与受欢迎程度有着显著的提升,这多半归功于它可以快速地被应用到几乎任何的数据科学问题中去,从而使人们能够高效快捷地获 ...