CF1139A Even Substrings
一个数是偶数等价于其最后一位为偶数(2/4/6/8/0)
从左往右扫一遍,如果一个数是奇数则直接跳过,偶数则加上它对答案的贡献
这里的贡献应该为以它结尾的数的个数,自然就是它的下标了(下标从1开始)
注意开long long
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 6;
int n;
char s[N];
ll ans;
int main() {
cin >> n;
scanf("%s", s + 1);
for (int i = 1; i <= n; i++)
if (!((s[i] - '0') & 1)) ans += i;
cout << ans << endl;
return 0;
}
CF1139A Even Substrings的更多相关文章
- CF1139A Even Substrings 题解
Content 有一个长度为 \(n\) 的数字串 \(s\),试求出代表偶数的子串个数. 数据范围:\(1\leqslant n\leqslant 65000\),\(s\) 仅包含数字 \(1\s ...
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- Leetcode: Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- CSU-1632 Repeated Substrings (后缀数组)
Description String analysis often arises in applications from biology and chemistry, such as the stu ...
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
- LA4671 K-neighbor substrings(FFT + 字符串Hash)
题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...
- 后缀数组---New Distinct Substrings
Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...
- Codeforces Round #258 D Count Good Substrings --计数
题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...
- SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转
694. Distinct Substrings Problem code: DISUBSTR Given a string, we need to find the total number o ...
随机推荐
- [HNOI2003]消防局的设立 树形dp // 贪心
https://www.luogu.org/problemnew/show/P2279 一开始就想到了贪心的方法,不过一直觉得不能证明. 贪心的考虑是在深度从深到浅遍历每个结点的过程中,对于每个没有覆 ...
- kettle连接mysql数据库并进行数据分析
1.数据库链接驱动 如果没有安装对应的数据库链接驱动,在数据库链接的过程中,可能会报某个数据库连接找不到的异常,因此需要下载对应驱动后(安装步骤可以参见“怎么在官网上下载java连接mysql的驱动j ...
- 2017-12-14python全栈9期第一天第八节之循环语句while
12,while. while 条件: 循环体 无限循环. 终止循环:1,改变条件,使其不成立. 2,break continue
- 机器学习-随机梯度下降(Stochastic gradient descent)
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- OpenStack的基础原理
OpenStack的基础原理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. OpenStack既是一个社区,也是一个项目和一个开源软件,它提供了一个部署云的操作平台或工具集.其 ...
- passat QA / error code 20190210
s 帕萨特B5 技术资料下载 https://pan.baidu.com/s/1KXYly7eGDUSI5QiLcz8fiQ 提取码: 1i7u 星期日,10,二月,2019,17:16:16:317 ...
- Nginx简单手册
Nginx 变量 变量名 注解 $arg_name 请求中的的参数名,即“?”后面的arg_name=arg_value形式的arg_name $args 请求中的参数值 $binary_remot ...
- HDU - 6314 Matrix(广义容斥原理)
http://acm.hdu.edu.cn/showproblem.php?pid=6314 题意 对于n*m的方格,每个格子只能涂两种颜色,问至少有A列和B行都为黑色的方案数是多少. 分析 参考ht ...
- initializer_list 列表初始化
initializer_list 列表初始化 用花括号初始化器列表初始化一个对象,其中对应构造函数接受一个 std::initializer_list 参数. #include <iostrea ...
- PHP7 学习笔记(十四)Reids 键空间通知配合TP5 实现分布式延时任务
测试环境:windows 10 + phpStudy 配置redis配置文件 redis.windows.conf notify-keyspace-events "Ex" 重启re ...