codeforces D. Count Good Substrings
http://codeforces.com/contest/451/problem/D
题意:给你一个字符串,然后找出奇数和偶数长度的子串的个数,这些字串符合,通过一些连续相同的字符合并后是回文串。
思路:因为这些字符串中的字符只有'a','b',所以首位相同的字串都可以满足,这样就分别统计奇数和偶数位置的字符的个数,然后相互组合就可以。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 100010
#define ll long long
using namespace std; char str[maxn];
ll o[maxn];
ll e[maxn]; int main()
{
cin>>str;
int k=strlen(str);
ll odd=;
ll even=;
memset(o,,sizeof(o));
memset(e,,sizeof(e));
for(int i=; i<k; i++)
{
odd++;
int x=str[i]-'a';
if(i%==)
{
odd+=o[x];
even+=e[x];
o[x]++;
}
else
{
odd+=e[x];
even+=o[x];
e[x]++;
}
}
printf("%I64d %I64d\n",even,odd);
return ;
}
codeforces D. Count Good Substrings的更多相关文章
- codeforces 451D Count Good Substrings
题意:给定一个字符串,求有多少个奇数子串和多少偶数子串为 “回文串” 这边回文串很特殊之含有 ab 两种字母 而且 相邻的字母相同则消去一个 一直到不存在相邻的相同. 思路: 在这种串 ...
- Codeforces Round #258 (Div. 2) D. Count Good Substrings 水题
D. Count Good Substrings 题目连接: http://codeforces.com/contest/451/problem/D Description We call a str ...
- 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 ...
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
- 【Leetcode_easy】696. Count Binary Substrings
problem 696. Count Binary Substrings 题意:具有相同个数的1和0的连续子串的数目: solution1:还不是特别理解... 遍历元数组,如果是第一个数字,那么对应 ...
- 696. Count Binary Substrings - LeetCode
Question 696. Count Binary Substrings Example1 Input: "00110011" Output: 6 Explanation: Th ...
- Codeforces Round #258 D Count Good Substrings --计数
题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...
- 【Codeforces 258D】 Count Good Substrings
[题目链接] http://codeforces.com/contest/451/problem/D [算法] 合并后的字符串一定是形如"ababa","babab&qu ...
- [LeetCode] Count Binary Substrings 统计二进制子字符串
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...
随机推荐
- 看懂下面C++代码才说你理解了C++多态虚函数!
#include <iostream> using namespace std ; class Father { private : virtual void Say() //只有添加 ...
- Sqlserver中实现oralce 数据库的rownumber
引用自:http://cai555.javaeye.com/blog/466033 方法1: with temp as ( select row_number() over(order by city ...
- apache目录及文件讲解
apache目录下bin,conf,htdocs,logs,modules讲解 bin: ab 压力测试工具 apachectl 启动命令 apxs ...
- BI任务列表
了解点击流系统和pv/uv的相关计算 关于pv的那些事!! ···············································2014-09-10 homework做了些什 ...
- a标签的简单用法
1.href="#"的作用:页面中有滚动,可以直接回到顶部. <a href="#">回到最顶端</a> 2.href="ur ...
- 在jsp中用EL 表达来获取表单中的参数
在一个JSP页面转到另一个JSP页面时,对表单中的参数用EL表达式提取为: <form action="sampleJsp.jsp" method="po ...
- jsoup:解析HTML用法小结
1.解析方式 (1)从字符串解析 ? 1 2 3 String html = "<html><head><title>First parse</ti ...
- AUTOTRACE Statistics常用列解释
AUTOTRACE Statistics常用列解释 序号 列名 解释 1 db block gets 从buffer cache中读取的block的数量 2 consistent gets 从buff ...
- Android模拟器对应的电脑快捷键说明
Home键(小房子键) 在键盘上映射的就是home键,这倒是很好记. Menu键 用于打开菜单的按键,在键盘上映射的是F2键,PgUp键同样可以.另外,看英文原文的意思,貌似这个键在某些机型上会被设计 ...
- 前端开发bower包管理器
Bower 是 twitter 推出的一款包管理工具,基于nodejs的模块化思想,他可以很好的帮助你帮你解决js的依赖管理,比如jquery angular bootstrap 等等. 可以很方便的 ...