【题目链接】

http://codeforces.com/contest/451/problem/D

【算法】

合并后的字符串一定是形如"ababa","babab",ab交替出现的字符串

那么,判断一段是否为回文,只需判断首尾字符是否相等即可

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + ; int i;
long long ans1,ans2;
char s[MAXN];
long long sum[][]; int main()
{ scanf("%s",s+);
for (i = ; i <= strlen(s + ); i++)
{
sum[i%][s[i]-'a']++;
if (i % == )
{
ans1 += sum[][s[i]-'a'];
ans2 += sum[][s[i]-'a'];
} else
{
ans1 += sum[][s[i]-'a'];
ans2 += sum[][s[i]-'a'];
}
}
printf("%I64d %I64d\n",ans1,ans2); return ; }

【Codeforces 258D】 Count Good Substrings的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

  3. 【codeforces 514C】Watto and Mechanism(字符串hash)

    [题目链接]:http://codeforces.com/contest/514/problem/C [题意] 给你n个字符串; 然后给你m个询问;->m个字符串 对于每一个询问字符串 你需要在 ...

  4. 【codeforces 768E】Game of Stones

    [题目链接]:http://codeforces.com/contest/768/problem/E [题意] NIM游戏的变种; 要求每一堆石头一次拿了x个之后,下一次就不能一次拿x个了; 问你结果 ...

  5. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【41.43%】【codeforces 560C】Gerald's Hexagon

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【25.64%】【codeforces 570E】Pig and Palindromes

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 742B】Arpa’s obvious problem and Mehrdad’s terrible solution

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【19.46%】【codeforces 551B】ZgukistringZ

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 安卓学习之学生签到APP(一)

    一.学生定位签到页面 具体实现步骤: 1.1 高德地图申请key 1.创建新应用 进入高德地图api控制台,创建一个新应用.如果您之前已经创建过应用,可直接跳过这个步骤. 2.添加新Key 在创建的应 ...

  2. 用js制作一个计算器

    使用js制作计算器 <!doctype html> <html lang="en"> <head> <meta charset=" ...

  3. 【原创】redhat5安装oracle10g

    安装缺失的包: 用 root 用户身份运行以下命令: rpm -q gcc make binutils openmotif setarch compat-db compat-gcc compat-gc ...

  4. hadoop job history server

    默认情况下是没有启动的,需要配置完后手工启动服务. 1. 修改mapred-site.xml,添加如下内容(cluster mode, RM) <property>     <nam ...

  5. 请不要继续使用VC6.0了!

    很多次和身边的同学交流,帮助同学修改代码,互相分享经验,却发现同学们依然在使用老旧的VC6.0作为编程学习的软件,不由得喊出:“请不要继续使用VC6.0了!”. VC6.0作为当年最好的IDE(集成开 ...

  6. Functor and Monad in Swift

    I have been trying to teach myself Functional Programming since late 2013. Many of the concepts are ...

  7. matlab学习下拉菜单Pop-Up Menu的基本用法

    创建下拉菜单,修改string的属性,tag改为kj1,value值如果是1就显示第一行的sin(x),是几就显示第几行 %可以更改value值var=get(handles.kj1,'value') ...

  8. ORACLE 查询不走索引的原因分析,解决办法通过强制索引或动态执行SQL语句提高查询速度

    (一)索引失效的原因分析: <>或者单独的>,<,(有时会用到,有时不会) 有时间范围查询:oracle 时间条件值范围越大就不走索引 like "%_" ...

  9. Git创建本地分支并关联远程分支(一)

    默认,git项目只有一个分支,就是master,我们当然可以在本地创建多个分支,并推送到远程git管理平台上,或者将远程git管理平台上的其他分支拉取到自己电脑上. 一.查看本地已有的分支 进入到项目 ...

  10. em与当前元素的不解之缘

    em是相对于当前元素的字体大小而言,比如font-size:14px;那么这个元素的1em=14px. 如果当前元素未定义字体大小,则会向上继承父元素的字体大小,如果当前元素的所有祖先元素都没有定义f ...