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\n",even,odd);
}

Codeforces Round #258 (Div. 2) D. Count Good Substrings 水题的更多相关文章

  1. Codeforces Round #258 (Div. 2) D. Count Good Substrings —— 组合数学

    题目链接:http://codeforces.com/problemset/problem/451/D D. Count Good Substrings time limit per test 2 s ...

  2. Codeforces Round #258 (Div. 2) A. Game With Sticks 水题

    A. Game With Sticks 题目连接: http://codeforces.com/contest/451/problem/A Description After winning gold ...

  3. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  4. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  5. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  6. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  7. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  8. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  9. Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题

    A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...

随机推荐

  1. 原始套接字-自定义IP首部和TCP首部

    /* ===================================================================================== * * Filenam ...

  2. python学习笔记7-excel操作

    一.操作excel import xlwt book = xlwt.Workbook() #新建一个excel sheet = book.add_sheet('sheet1') #添加一个sheet页 ...

  3. 用matplotlib绘制每次交易的盈亏三角形

    用matplotlib绘制每次交易的盈亏三角形 结果: 代码: python def plot_trade_triangle(self): # plot each trade as a trade-t ...

  4. 重启sqlserver服务 命令

    在控制台(CMD)中运行: net stop mssqlserver     net start mssqlserver

  5. rsync更改端口后的同步办法

    rsync有两种常用的认证方式,一种为rsync-daemon方式,另外一种则是ssh. 在一些场合,使用rsync-daemon方式会比较缺乏灵活性,ssh方式则成为首选.但是今天实际操作的时候发现 ...

  6. hibernate的多对多关联映射

    在我们实际项目中,多对多的情况也时长存在,比如最常见的就是系统管理的五张表,如下面的一个结构: 在本文学习hibernate多对多关联映射的实验中我简单的写几个字段,达到学习目的即可. 1.多对多的关 ...

  7. flask基础之LocalProxy代理对象(八)

    前言 flask框架自带的代理对象有四个,分别是request,session,g和current_app,各自的含义我们在前面已经详细分析过.使用代理而不是显式的对象的主要目的在于这四个对象使用太过 ...

  8. usb_control_msg函数用法和说明

    usb_control_msg是没有用到urb的在USB中简单进行发送和接收的一种机制,用于少量的数据通信.原型为:  程序代码 linux+v2.6.35/drivers/usb/core/mess ...

  9. linux sftp安装【转】

    工具:虚拟机:VMware Workstation Pro.操作系统:CentOS-6.4-x86_64-minimal.终端模拟器:Xshell 5 .ftp:filezilla 一.让虚拟机联网 ...

  10. 解决方案:centos运行shell脚本时报“$'\r': 未找到命令”

    =============================================== 2018/9/12_第1次修改                       ccb_warlock == ...