题目大意:给你一个长度为$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. ICEM-带把圆环

    原视频下载地址:https://pan.baidu.com/s/1pKSXyR5 密码: dynm

  2. 2018-2019-2 网络对抗技术 20165322 Exp7 网络欺诈防范

    2018-2019-2 网络对抗技术 20165322 Exp7 网络欺诈防范 目录 实验原理 实验内容与步骤 简单应用SET工具建立冒名网站 ettercap DNS spoof 结合应用两种技术, ...

  3. win10 eclipse连接虚拟机ubuntu中的hdfs

    1.eclipse安装连接hadoop的插件hadoop-eclipse-plugin-2.6.0(注意自己hadoop的版本) 将该插件放在eclipse安装路径的plugins文件夹中. ps:我 ...

  4. 2019 SDN上机第一次实验作业

    1. 安装轻量级网络仿真工具Mininet 先从GitHub上获取mininet源码,再输入命令进行安装,代码分别如下: git clone https://github.com/mininet/mi ...

  5. DNGuard HVM Unpacker(3.71 trial support and x64 fixed)

    DNGuard HVM Unpacker(3.71 trial support and x64 fixed) Gr8 news. Finally got the x64 crash fixed. DN ...

  6. selenium操作下拉滚动条的几种方法

    数据采集中,经常遇到动态加载的数据,我们经常使用selenium模拟浏览器操作,需要多次下拉刷新页面才能采集到所有的数据,就此总结了几种selenium操作下拉滚动条的几种方法 我这里演示的是Java ...

  7. P1310 表达式的值

    P1310 表达式的值 题解 1.假设有两个布尔变量 x , y  x0表示使得x=0的方案数 x1表示使得x=1的方案数 y0表示使得y=0的方案数 y1表示使得y=1的方案数 | 按位或 & ...

  8. Alternatives to Activiti for all platforms with any license

    Activiti Activiti is a light-weight workflow and Business Process Management (BPM) Platform targeted ...

  9. Springmvc request response log

    Log Incoming Requests In Spring | Java Development Journalhttps://www.javadevjournal.com/spring/log- ...

  10. AI学习网址记录

    https://ai.yanxishe.com/ https://ai.yanxishe.com/page/blogDetail/14365 GAN网络 对抗式生成网络-图像超分辨及图像修复 完全可见 ...