• Codeforces Round #258 (Div. 2) D. Count Good Substrings 水题


    D. Count Good Substrings

    题目连接:

    http://codeforces.com/contest/451/problem/D

    Description

    We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".

    Given a string, you have to find two values:

    the number of good substrings of even length;
    the number of good substrings of odd length. 
    

    Input

    The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).

    Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.

    Output

    Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length.

    Sample Input

    bb

    Sample Output

    1 2

    Hint

    题意

    他定义了一个叫做good串的东西,就是重叠的字符就算作一个,然后如果重叠算一个,且最后是回文串的话,那么他就是好的。

    现在给你一个串,问你他的奇数长度good,和偶数长度good各有多少个。

    题解:

    由于只含有ab,所以这种回文串一定是ababababa这种的,那么只要两端相同就好了。

    然后我们统计一下就行。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e5+7;
    char s[maxn];
    long long cnt[3][3];
    int main()
    {
        scanf("%s",s);
        int len=strlen(s);
        long long odd=0,even=0;
        for(int i=0;i<len;i++)
        {
            cnt[s[i]-'a'][i%2]++;
            even+=cnt[s[i]-'a'][1-i%2];
            odd+=cnt[s[i]-'a'][i%2];
        }
        printf("%lld %lld
    ",even,odd);
    }
  • 相关阅读:
    SQL中UNION的使用
    [转]身份证号准确性检测
    shell中if/seq/for/while/until
    shell中数字、字符串、文件比较测试
    shell简介及变量的定义查看撤销
    grep/字符/次数匹配/锚定符/小大括号/wc/tr/cut/sort/uniq
    linux全局和个人配置文件说明
    linux文件的3个时间和7种文件类型
    linux常用配置文件和命令总结
    目录方式扩展swap分区大小
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5856411.html
Copyright © 2020-2023  润新知