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. c#的事件用法——实现下载时发生的事件

    //下载时发出的事件 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  2. jdk 动态代理实现对目标对象的增强

    因为学习 spring框架的 AOP 所以,这里复习下动态代理,但是 spring 的底层动态代理实现是 cglib,jdk 这种呢可以引导新手入门 spring AOP 横向抽取机制 最典型的应用当 ...

  3. [转载]AngularJS 开发者最常犯的 10 个错误

    http://www.oschina.net/translate/top-10-mistakes-angularjs-developers-make

  4. 在ASP.Net中两种利用CSS实现多界面的方法

    通过使页面动态加载不同CSS实现多界面(类型于csdn的blog): 方法一: <%@page language="C#"%><%@import namespac ...

  5. Hacking Using Beef-Xss

    1.环境 hacker:192.168.133.128 os:Kali victims:192.168.133.1    os:win8 2.前期配置 首先进入beef-xss主目录,编辑配置文件,将 ...

  6. 【Python】Flask系列-模板笔记

    Jinja2模板 Jinja2模板传参 如何渲染模板: 模板放在templates文件夹下 从flask中导入render_template函数. 在视图函数中,使用render_template函数 ...

  7. Git 使用规范流程【转】

    转自:http://www.ruanyifeng.com/blog/2015/08/git-use-process.html 作者: 阮一峰 日期: 2015年8月 5日 团队开发中,遵循一个合理.清 ...

  8. 如何将IOS版本的更新下载文件指向到自己的服务器

    针对那些使用企业签名但是没有发布到AppSotre的IOS版本APP自动更新问题解决方案: 在apicloud中是这样说明的: 因为要填写plist地址所以不能向安卓那样直接填写服务器文件地址,但是直 ...

  9. js input输入框的总结

    一.输入框只能输入数字 原文:https://www.cnblogs.com/sese/p/5872144.html 分享下js限制输入框中只能输入数字的方法,包括整数与小数,分享几个例子,有需要的朋 ...

  10. 0行代码实现任意形状图片展示--android-anyshape

    前言 在Android开发中, 我们经常会遇到一些场景, 需要以一些特殊的形状显示图片, 比如圆角矩形.圆形等等.关于如何绘制这类形状, 网上已经有很多的方案,比如自定义控件重写onDraw方法, 通 ...