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 ...
随机推荐
- chrome浏览器安装不上的惨痛经历
项目在赶进度的时候,手贱把chrome的一些文件删除了,整个浏览器都没法打开 决定重装下,但是连卸载的功能都打不开了 上网重新下载了个安装包,发现安装包都打不来 很绝望,查了很多资料 很多人说要删除注 ...
- NLTK的安装
一.NLTK:Natural Language Toolkit(自然语言工具包) 下载:http://www.nltk.org pip install nltk 二.使用 import nltk nl ...
- ansible-playbook 单个yml文件部署tomcat简单示例
#单yaml配置[root@jenkins pb]# cat tomcat.yml --- - hosts: eee vars: #设置变量 war_files: /var/lib/jenkins/w ...
- Linux top、VIRT、RES、SHR、SWAP(S)、DATA Memory Parameters Detailed
catalog . Linux TOP指令 . VIRT -- Virtual Image (KB) . RES -- Resident size (KB) . SHR -- Shared Memor ...
- 腾讯云ping wget yum 常用命令设置问题
遇到ping wget yum 命令不能正常使用的情况是因为腾讯云有些配置: root执行如下即可: wget -q http://mirrors.tencentyun.com/install/sof ...
- HTML5 离线缓存Appcache
创建一个和html同名的manifest文件,比如页面为index.html,那么可以建一个index.manifest的文件,然后给index.html的html标签添加如下属性即可: <ht ...
- java NIO入门【原】
server package com.server; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import jav ...
- ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge(状压dp)
https://nanti.jisuanke.com/t/30994 题意 给你n个题目,对于每个题目,在做这个题目之前,规定了必须先做哪几个题目,第t个做的题目i得分是t×ai+bi问最终的最大得分 ...
- Linux 命令详解(十二)Systemd 入门教程:使用定时器发送邮件(mail)
Systemd 定时器教程:http://www.ruanyifeng.com/blog/2018/03/systemd-timer.html 一.定时任务 Systemd 定时任务:每小时发送一封电 ...
- [Android] Android 注解绑定UI View组件库 ButterKnife 的使用
ButterKnife是一个专注于Android系统的View注入框架,以前总是要写很多findViewById来找到View对象,有了ButterKnife可以很轻松的省去这些步骤.是大神JakeW ...