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 ...
随机推荐
- 使用泛型定义一个可重用的Dao
dao用来和数据库进行交互,一个项目中,可能有用户表,产品表等等,不可能为每一个表都建立一个dao,使用泛型可以实现通吃. UserDao.java public class UserDao < ...
- spring+hibernate+jpa+Druid的配置文件,spring整合Druid
spring+hibernate+jpa+Druid的配置文件 spring+hibernate+jpa+Druid的完整配置 spring+hibernate+jpa+Druid的数据源配置 spr ...
- 鼠标移入 移出div div会消失的处理
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- VB------VS2012 IDE
当编辑器的前面出现很多小点不影响 运行的时候 Ctrl+E+S就可以取消
- 关于ASP.Net中路径的问题
比如你的工程是Webapplication1(url是:http://localhost/webapplication1/webform1.aspx) Request.ApplicationPath ...
- AsyncTask理解- Day36or37
AsyncTask理解- Day36or37 mobile 5.0 1.手机归属地查询 AtoolsActivity Assets目录特点 该文件是原生文件,不会对里面的文件进行编码 该文件只支持读取 ...
- Using native GDI for text rendering in C#
Using native GDI for text rendering in C# Aug12by Arthur To complete my previous post on text render ...
- CI 笔记7,easyui 异步加载
在做后台导航时,需要异步加载,pid和id的循环问题,在controller中,建立另外一个方法,嵌套循环,查找是否pid〉1. public function nav_list() { $this- ...
- 系统设计 - IOS 程序插件及功能动态更新思路
所用框架及语言 IOS客户端-Wax(开发愤怒的小鸟的连接Lua 和 Objc的框架),Lua,Objc, 服务端-Java(用于返回插件页面) 由 于Lua脚本语言,不需要编译即可运行 ...
- Ubuntu系列Crontab日记记录
修改rsyslog文件,将/etc/rsyslog.d/50-default.conf 文件中的#cron.*前的#删掉 重启rsyslog服务service rsyslog restart 重启cr ...