CodeForces Round #548 Div2
http://codeforces.com/contest/1139
You are given a string s=s1s2…sns=s1s2…sn of length nn, which only contains digits 11, 22, ..., 99.
A substring s[l…r]s[l…r] of ss is a string slsl+1sl+2…srslsl+1sl+2…sr. A substring s[l…r]s[l…r] of ss is called even if the number represented by it is even.
Find the number of even substrings of ss. Note, that even if some substrings are equal as strings, but have different ll and rr, they are counted as different substrings.
The first line contains an integer nn (1≤n≤650001≤n≤65000) — the length of the string ss.
The second line contains a string ss of length nn. The string ss consists only of digits 11, 22, ..., 99.
Print the number of even substrings of ss.
4 1234
6
4 2244
10
In the first example, the [l,r][l,r] pairs corresponding to even substrings are:
- s[1…2]s[1…2]
- s[2…2]s[2…2]
- s[1…4]s[1…4]
- s[2…4]s[2…4]
- s[3…4]s[3…4]
- s[4…4]s[4…4]
In the second example, all 1010 substrings of ss are even substrings. Note, that while substrings s[1…1]s[1…1] and s[2…2]s[2…2] both define the substring "2", they are still counted as different substrings.
代码:
#include <bits/stdc++.h> using namespace std; int N; string s; int main() { cin >> N >> s; int ans = 0; for(int i = 0; i < N; i ++) { if((s[i] - '0') % 2 == 0) ans += (i + 1); } printf("%d\n", ans); return 0; }
(其实... 说不很清楚为什么是这样 直觉??? 灵魂 coder 吧)
- mysql下mysqladmin日常管理命令总结
- Ubuntu下SVN安装和配置
- mysql表名忽略大小写问题记录
- 当wcf遇到JSON ?
- 从MapX到MapXtreme2004[2]-图层操作
- Nginx+keepalived双机热备(主主模式)
- 用正则表达式完成简单公式的替换计算
- Linux下误删除后的恢复操作(ext3/ext4)
- 部署Linux下的man慢查询中文帮助手册环境
- 想修改CSS
- linux下sendmail邮件系统安装操作记录
- 定时备份脚本分享(网站数据和数据库数据)
- 大型分布式服务器架构原理解析
- silverlight中用代码动态控制Storyboard(动画)属性的三种方法
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- LeetCode题目26:删除排序数组中的重复项
- PCA算法原理及实现
- LeetCode题目27:移出元素
- LeetCode题目28:实现strStr()
- LeetCode题目29:两数相除
- LeetCode题目30:串联所有单词的子串
- LeetCode题目31:下一个排列
- LeetCode题目33:搜索旋转排序数组
- LeetCode题目34:在排序数组中查找元素的第一个和最后一个位置
- LeetCode题目35:搜索插入位置
- LeetCode题目36:有效的数独
- 你必须掌握动态规划——LeetCode题目5:最长回文子串
- 有意思的难题——LeetCode题目37:解数独
- 源码分析-分布式链路追踪:Skywalking存储插件能力-elasticsearch
- mongodb 4.0副本集搭建