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\n",even,odd);
}
Codeforces Round #258 (Div. 2) D. Count Good Substrings 水题的更多相关文章
- 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 ...
- Codeforces Round #258 (Div. 2) A. Game With Sticks 水题
A. Game With Sticks 题目连接: http://codeforces.com/contest/451/problem/A Description After winning gold ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- ASP.NET MVC学习(四)之视图View
1.视图 2.强类型视图 3.@RenderSection("HeaderSection", false) @RenderBody() 4.子行为 5.ASP.NET MV ...
- Asp.net操作Word文档,原来这么简单啊!
引用Word对象库文件 具体做法是打开菜单栏中的项目>添加引用>浏览,在打开的“选择组件”对话框中找到MSWORD.OLB后按确定即可引入此对象库文件,vs.net将会自动将库文件转化为 ...
- Visual Studio 配置 Avalon 自动补全
以VS2013为例: 1.关闭 Visual Studio 2.打开 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Packa ...
- Linux系统的快速启动机制(内核切换) 【转】
转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26807463&id=4187846 原文地址:Linux系统的 ...
- 诡异的Linux磁盘空间被占用问题,根目录满了,df和du占用不一样【转】
新公司的测试机磁盘空间空余很小,日志很多,也很大,做个日志压缩脚本,在夜里4:30自动运行,第二天后发现磁盘空间又满了,只好删除没用的日志,清空空间,可诡异的是怎么删除没用的文件,空间还是占用很大.如 ...
- maven:多个镜像配置
<mirrors> <mirror> <id>nexus-aliyun</id> <mirrorOf>nexus-aliyun</mi ...
- Python学习系列之(二)图解Windows8.1下安装Django
一. 下载 去官网下载https://www.djangoproject.com/download/最新版,最新版本是1.6 二. 安装: 将下载下来的Django-1.6.tar.gz解压到D盘,接 ...
- .NetCore 中使用AppMetrics向InfluxDB中添加监控数据并通过Grafana图像分析
考虑到分布式部署监控环境是所有的请求情况,所以这一块一般在网关GateWay里面加比较省事,聚合在一起的,如果放在api服务中,如果只有1个还好,一旦部署Node多是很痛苦的事情 这天需要添加的Nug ...
- 《python源码剖析》,看看
这书高级了,有点超出理解能力. 但走出舒适区,不是大家都在说的么?:) 看完了些章节,还是很有收获的, 截图存照.
- Linux系统运维笔记(三),设置IP和DNS
Linux系统运维笔记(三),设置IP和DNS 手工配置静态的IP地址 也就是手工配置IP地址.子网掩码.网关和DNS. vi /etc/sysconfig/network-scripts/ifcfg ...