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. CGI与FastCGI 转

    CGI与FastCGI 当我们在谈到cgi的时候,我们在讨论什么 最早的Web服务器简单地响应浏览器发来的HTTP请求,并将存储在服务器上的HTML文件返回给浏览器,也就是静态html.事物总是不 断 ...

  2. 将Java应用注册为后台服务

    项目中有一个java应用程序,交付后用户要求要把这个程序做成后台服务程序,即:系统启动后该程序可以自动启动,并且在前台不要出现运行窗口,维护人员只要在“服务管理”(Windows)中选择启动或停止即可 ...

  3. git提交时的冲突处理

    转自http://www.cnblogs.com/mengdd/p/3585038.html 当两条分支对同一个文件的同一个文本块进行了不同的修改,并试图合并时,Git不能自动合并的,称之为冲突(co ...

  4. Node.js + Express + Mongodb 开发搭建个人网站(二)

    二.路由 1.打开 routes/index.js ,这个意思就是  捕获到访问主页的get请求: 并通过 app.js 分配到对应的路由里: 看到这里,打开 http://127.0.0.1:300 ...

  5. .NET设计模式(4):建造者模式(Builder Pattern)

    ):建造者模式(Builder Pattern)    .建造者模式的使用使得产品的内部表象可以独立的变化.使用建造者模式可以使客户端不必知道产品内部组成的细节. 2.每一个Builder都相对独立, ...

  6. windows server 2003 系统重装蓝屏

    错误码:0X0000007B 这个代码和硬盘有关系,不过不用害怕,不是有坏道了,是设置问题或者病毒造成的硬盘引导分区错误.如果您在用原版系统盘安装系统的时候出这个问题,那说明您的机器配置还是比较新的, ...

  7. C#中的委托范例学习

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  8. SQL Server2008 附加数据库失败 错误代码5120

    由于目录权限不够导致 ,解决办法:将文件所在的文件夹增加everyone 并且赋予完全控制权限问题解决

  9. Cisco AnyConnect “Failed to initialize connection subsystem”的解决方案

    Per Cisco: Microsoft has released a fix-it patch providing a workaround for this issue. See KB# 3023 ...

  10. C++和MATLAB混合编程-DLL

    先小话一下DLL,DLL是动态链接库,是源代码编译后的二进制库文件和程序接口,和静态链接库不同的是,程序在编译时并不链接动态链接库的执行体,而是在文件中保留一个调用标记,在程序运行时才将动态链接库文件 ...