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. android开发之记录ListView滚动位置

    这个问题本身不难,但是由于项目中的需求太过于复杂,结果导致这个问题变得不是那么容易实现.在网上一搜,结果如下: 我不知道是who copy who?反正介绍的所谓的三种方法,第一种都是无法运行的,很明 ...

  2. Mysql解压版的安装

    Mysql解压版的安装 ——@梁WP 1.解压mysql到合适的地方 2.右击计算机-属性-高级系统设置-高级-环境变量,弹出“环境变量”对话框,修改下面的系统变量 3.新建MYSQL_HOME变量, ...

  3. php 5.3起弃用session_register

    最近下了dedecms V5.7时,在登陆后台时,用户名和密码也没错,就是跳转不走,进不了后台管理页面,追踪了好久才发现根目录/include/userlogin.class.php中289行左右的位 ...

  4. mybatis缓存清除方法

    String cacheName = IWenshiduDao.class.getName(); Ehcache cache = CacheManager.create().getEhcache(ca ...

  5. float浮动之后高度自适应失效解决方案

    float浮动之后高度自适应失效解决方案 >>>>>>>>>>>>>>>>>>>> ...

  6. 高效删除 ListItem

    The most efficient way to a lot of transaction in SharePoint is using of SPWeb.ProcessBatchData meth ...

  7. java web hello world

    首先在eclipse 里面创建一个java 动态项目, 记住路径,这里是直接通过根目录直接访问的webContent目录下面 的文件, 创建好后 ,在本地配置Tomcat服务器, 将server加入到 ...

  8. .Net程序员学习Linux(三)

      基础命令 ll 文件名 命令可以查看文件的大小 file 文件名 可以看到文件后缀,大小 压缩与解压工具 这些压缩工具按照我理解应该是很少单独拿出来用,应该是需要配合其他命令或者工具来使用 gzi ...

  9. [Json] C#ConvertJson|List转成Json|对象|集合|DataSet|DataTable|DataReader转成Json (转载)

    点击下载 ConvertJson.rar 本类实现了 C#ConvertJson|List转成Json|对象|集合|DataSet|DataTable|DataReader转成Json|等功能大家先预 ...

  10. How to hanganalyze and systemstate dumps

    Oracle support request hang analysis and system state dumps when rasing SR. One 10.1 or higher versi ...