题目地址: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的更多相关文章

  1. CF1139A Even Substrings 题解

    Content 有一个长度为 \(n\) 的数字串 \(s\),试求出代表偶数的子串个数. 数据范围:\(1\leqslant n\leqslant 65000\),\(s\) 仅包含数字 \(1\s ...

  2. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  3. Leetcode: Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  4. CSU-1632 Repeated Substrings (后缀数组)

    Description String analysis often arises in applications from biology and chemistry, such as the stu ...

  5. CF451D Count Good Substrings (DP)

    Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...

  6. LA4671 K-neighbor substrings(FFT + 字符串Hash)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...

  7. 后缀数组---New Distinct Substrings

    Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...

  8. Codeforces Round #258 D Count Good Substrings --计数

    题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...

  9. SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转

    694. Distinct Substrings Problem code: DISUBSTR   Given a string, we need to find the total number o ...

随机推荐

  1. Shiro进行简单的身份验证(二)

    一个Realm数据源: shiro.ini: [users] wp=123456 main方法执行认证: package com.wp.shiro; import org.apache.shiro.S ...

  2. svn 基础

    安装,略过. 快速创建.配置及启动项目 创建项目 svnadmin create /home/svn/project_name #创建名为project_name的项目(/home/svn为自定义创建 ...

  3. 《玩转Django2.0》读书笔记-编写URL规则

    <玩转Django2.0>读书笔记-编写URL规则 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. URL(Uniform Resource Locator,统一资源定位 ...

  4. Visual Studio连接到TFS

    我在学校自己使用git,公司使用VSS,然后这个项目又使用TFS.Visual Studio连接到TFS是这样滴 1.点连接到团队项目 2.添加TFS服务器的url,写到你的http:XXX/tfs就 ...

  5. eclipse设置是否自动跳转切换到debug视图模式

    之前一直用公司二次封装的eclipse,这几天用原生态的eclipse,刚开始使用eclipse进行调试时,会自动跳转到debug视图.后来不小心关闭了,就不会自动切换到debug视图. 这个小问题之 ...

  6. setAttribute和setParameter方法的区别

    getAttribute表示从request范围取得设置的属性,必须要先setAttribute设置属性,才能通过getAttribute来取得,设置与取得的为Object对象类型 getParame ...

  7. Hadoop记录-HDFS balancer配置

    HDFS balancer配置(可通过CM配置)dfs.datanode.balance.max.concurrent.moves 并行移动的block数量,默认5 dfs.datanode.bala ...

  8. appcms SSRF 绕过漏洞[转载]

    漏洞 <?php if(isset($_GET['url']) && trim($_GET['url']) != '' && isset($_GET['type' ...

  9. Spring事物的属性

    链接:https://www.nowcoder.com/questionTerminal/1c65d30e47fb4f59a5e5af728218cac4?orderByHotValue=2& ...

  10. 绕不开的hadoop

    安装 jdk 1.8 # 官网下载可能比较慢,请自行搜索国内镜像源 wget http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a ...