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 ...
随机推荐
- 以太网 ------ Auto-Negotiation(自动协商)
说起自动协商(Auto-negotiation),我想很多人都不会陌生.当你把你PC机器上的网卡通过一段双绞线连接到某个交换机的某个端口的时候,如果你的网卡和交换机都支持自动协商功能的话,一件有趣的事 ...
- 【SQL】SqlServer中Group By后,字符串合并
参考: 1.SQL查询语句 group by后, 字符串合并 2.sql for xml path用法 #需求: 合并列值 表结构,数据如下: id value ----- ------ aa bb ...
- JAVA核心技术I---JAVA基础知识(数字相关类)
一:相关数字类 –整数 Short, Int, Long –浮点数 Float, Double –大数类 BigInteger(大整数), BigDecimal(大浮点数) –随机数类 Random ...
- pom大全
springboot集合 父模块 <parent> <groupId>org.springframework.boot</groupId> <artifact ...
- 详解Linux内核红黑树算法的实现
转自:https://blog.csdn.net/npy_lp/article/details/7420689 内核源码:linux-2.6.38.8.tar.bz2 关于二叉查找树的概念请参考博文& ...
- hibernate validator【原】
hibernate validator 功能 在开发中经常做一些字段校验的功能,比如非空,长度限制,邮箱验证等等,为了省掉这种冗长繁琐的操作,hibernate validator提供了一套精简的注释 ...
- 【leetcode-101】 对称二叉树
101. 对称二叉树 (1过) 给定一个二叉树,检查它是否是镜像对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [ ...
- Linux基础(一)系统api与库函数的关系
1. 系统api与库函数的关系 man 2 open 1.1 open 1.2 read/write 实现cat功能 #include <stdio.h> #include <uni ...
- 网络编程之Socket & ServerSocket
网络编程之Socket & ServerSocket Socket:网络套接字,网络插座,建立网络通信连接至少要一对端口号(socket).socket本质是编程接口(API),对TCP/IP ...
- js中文编码到C#后台解码
escape() 方法: 采用ISO Latin字符集对指定的字符串进行编码.所有的空格符.标点符号.特殊字符以及其他非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编 ...