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的更多相关文章

  1. codeforces 451D Count Good Substrings

    题意:给定一个字符串,求有多少个奇数子串和多少偶数子串为 “回文串”   这边回文串很特殊之含有  ab  两种字母  而且  相邻的字母相同则消去一个  一直到不存在相邻的相同. 思路:  在这种串 ...

  2. 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 ...

  3. 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 ...

  4. CF451D Count Good Substrings (DP)

    Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...

  5. 【Leetcode_easy】696. Count Binary Substrings

    problem 696. Count Binary Substrings 题意:具有相同个数的1和0的连续子串的数目: solution1:还不是特别理解... 遍历元数组,如果是第一个数字,那么对应 ...

  6. 696. Count Binary Substrings - LeetCode

    Question 696. Count Binary Substrings Example1 Input: "00110011" Output: 6 Explanation: Th ...

  7. Codeforces Round #258 D Count Good Substrings --计数

    题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...

  8. 【Codeforces 258D】 Count Good Substrings

    [题目链接] http://codeforces.com/contest/451/problem/D [算法] 合并后的字符串一定是形如"ababa","babab&qu ...

  9. [LeetCode] Count Binary Substrings 统计二进制子字符串

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

随机推荐

  1. Mysql show Status参数详解

    状态名 作用域 详细解释 Aborted_clients Global 由于客户端没有正确关闭连接导致客户端终止而中断的连接数 Aborted_connects Global 试图连接到MySQL服务 ...

  2. visualvm

    http://visualvm.java.net/features.html http://visualvm.java.net/zh_CN/gettingstarted.html

  3. 启动MYSQL密码审计插件

    http://www.innomysql.com/article/25717.html [root@server-mysql plugin]# pwd /usr/local/mysql56/lib/p ...

  4. Eclipse3.7中搭建Android开发环境文档教程和视频教程

    1.下载Eclipse3.7,登录http://www.eclipse.org/downloads/,下载Eclipse Classic 3.7: 2.安装ADT插件:下载好Eclipse后解压,运行 ...

  5. [转载]Access to the path '' is denied.解决方案

    原文地址:Access to the path '' is denied.解决方案作者:趴着墙等红杏 ccess to the path '路径' is denied.我在网上找了很多资料,最后终于解 ...

  6. js--小结①

  7. 滚动效果,marquee便签

    语法: <marquee></marquee> 例子: <marquee><font size=+3 color=red>Hello, World< ...

  8. $(obj).data() 绑定和获取数据的应用

    1.解说 data() 方法向被选元素附加数据,或者从被选元素获取数据. 例如:$("#id").data("name","xiao"); ...

  9. iOS 知识-常用小技巧大杂烩

    原文链接:http://www.jianshu.com/p/7c3ee5e67d03. 自己看的. 1,打印View所有子视图 po [[self view]recursiveDescription] ...

  10. artDialog.js的使用

    开发项目中用到了artDialog.js,从而专门学习一下如何配置和使用. 一.artDialog是什么 artDialog是一个精巧的web对话框组件,压缩后只有十多KB,并且不依赖其他框架. 二. ...