题目大意:给你一个长度为$n$($n$为偶数)的字符串,且这个字符串仅由$'a'$与$'b'$两种字符组成,要你用最少的操作次数使得 $s[i]!=s[i-1] (i/2=0,1≤i≤n)$(若字符串从1开始),并输出更改后的串

大水题?两个两个一跳,相等就把其中一个换一下。

上代码:

#include<cstdio>

inline int read(){
int r=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9')r=(r<<1)+(r<<3)+c-'0',c=getchar();
return r*f;
} int n,ans; char s[200002],ab[2]={'a','b'}; int main(){
scanf("%d\n",&n);
scanf("%s",s);
for(int i=1;i<n;i+=2)
if(s[i]==s[i-1])s[i-1]=ab[(s[i-1]-'a')^1],ans++;//相等就换,操作数加1
printf("%d\n%s",ans,s);
return 0;
}

  

题解 CF1216A 【Prefixes】的更多相关文章

  1. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  2. Codeforces 381 简要题解

    做的太糟糕了...第一题看成两人都取最优策略,写了个n^2的dp,还好pre-test良心(感觉TC和CF的pretest还是很靠谱的),让我反复过不去,仔细看题原来是取两边最大的啊!!!前30分钟就 ...

  3. Shortest Prefixes(trie树唯一标识)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15948   Accepted: 688 ...

  4. Codeforces 1092C Prefixes and Suffixes(思维)

    题目链接:Prefixes and Suffixes 题意:给定未知字符串长度n,给出2n-2个字符串,其中n-1个为未知字符串的前缀(n-1个字符串长度从1到n-1),另外n-1个为未知字符串的后缀 ...

  5. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

  6. POJ 2001 Shortest Prefixes 【 trie树(别名字典树)】

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15574   Accepted: 671 ...

  7. CoderForces Round526 (A~E)题解

    A. The Fair Nut and Elevator time limit per test 1 second memory limit per test 256 megabytes input ...

  8. codeforces 380A Sereja and Prefixes (递归)

    题目: A. Sereja and Prefixes time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. POJ 2001 Shortest Prefixes (Trie)

    题目链接:POJ 2001 Description A prefix of a string is a substring starting at the beginning of the given ...

随机推荐

  1. “都是为了生活”小组 选题 Scrum立会报告+燃尽图 01

    作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/8683. 由于团队账号申请博客未通过网站审核,无法写博或加入班级,第一次立会 ...

  2. html5中section元素详解

    html5中section元素详解 一.总结 一句话总结: section元素 用来定义文章中的章节(通常应该有标题和段落内容) section元素的作用就是给内容分段,给页面分区 1.section ...

  3. No module named 'lsb_release'

    python3.7安装后提示 No module named 'lsb_release' 修改"/usr/bin/lsb_release" #!/usr/bin/python3.5 ...

  4. AXURE RP8 - 实战手册 网站和APP原型制作案例精粹

    扫码时备注或说明中留下邮箱 付款后如未回复请至https://shop135452397.taobao.com/ 联系店主    

  5. Java字节码增强探秘

    Java字节码增强探秘 https://mp.weixin.qq.com/s/CH9D-E7fxuu462Q2S3t0AA

  6. gpload导入常见问题汇总

    gpload导入常见问题汇总 java写文件后使用gpload命令导入greenplum: 问题一: 报错信息:invalid byte sequence for encoding "UTF ...

  7. ubuntu设置开机启动后命令行界面

    author:headsen chen date: 2019-09-19  14:23:31 在字符界面(即命令行界面)输入命令: 设置为字符界面的命令:sudo systemctl set-defa ...

  8. Python判断是否是闰年

    year = 2012 if year % 100 != 0 and year % 4 == 0: print('闰年') elif year % 100 == 0 and year % 400 == ...

  9. CDH 部署 Hadoop:5.开始安装

    Cloudera Enterprise 6.2.x   或者参考https://blog.csdn.net/shawnhu007/article/details/52579204 第零步:优化相关 e ...

  10. pycharm怎么修改python路径

    今天安装Django的时候遇到了python版本冲突,找不到python路径,所以又重新安装了一个python3.6.5 安装完之后,突然发现自己的pycharm是之前Anaconda的3.5版本,那 ...