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 ...
随机推荐
- Python之字符编码与文件操作
目录 字符编码 Python2和Python3中字符串类型的差别 文件操作 文件操作的方式 文件内光标的移动 文件修改 字符编码 什么是字符编码? ''' 字符编码就是制定的一个将人类的语言的字符与二 ...
- 解析:为什么程序员应该有一台Mac个人电脑?
对于开发来讲,使用Mac电脑的好处,下面简单列举几个: 首先,macOS很安全和稳定,Mac 系统的底层是最原始的unix操作系统,很多大型的银行和军工企业都是这个操作系统,安全性很高,基本不需要安装 ...
- 全局拦截各种http请求
http请求无非就是ajax.src.href.表单 function hookAJAX() { XMLHttpRequest.prototype.nativeOpen = XMLHttpReques ...
- 【SQL】数据库中的五种约束
#五大约束 1.主键约束(Primay Key Coustraint) 唯一性,非空性 2.唯一约束 (Unique Counstraint)唯一性,可以空,但只能有一个 3.检查约束 (Check ...
- Java Web之EL
<%-- Created by IntelliJ IDEA. User: Vae Date: 2019/1/2 Time: 12:19 To change this template use F ...
- JAVA-获取 JDK 动态代理生成的 Class 文件
可指定路径 import sun.misc.ProxyGenerator; import java.io.FileOutputStream; import java.io.IOException; i ...
- CSS3 vmax的用法
1. calc() calc():在流体布局上,可以通过calc()计算得到元素的宽度. 2. vw/vh/vmin/vmax的使用 vw/vh/vmin/vmax是视窗单位,也是相对单位.相对的不是 ...
- go结构体方法
Golang中的方法是作用在特定类型的变量上,因此自定义类型,都可以有方法,而不仅仅是struct. 定义格式 func (var *Struct_Name) FuncName( var0, var1 ...
- Mysql查看表的建表语句
已查询Test的建表语句为例: SHOW CREATE TABLE TEST
- Timus 1132 Square Root(二次剩余)
http://acm.timus.ru/problem.aspx?space=1&num=1132 题意: 求 x^2 ≡ n mod p p是质数 的 解 本题中n>=1 特判p=2 ...