题目大意:给你一个长度为$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. Docker hello workd

    Docker 允许你在容器内运行应用程序, 使用 docker run 命令来在容器内运行一个应用程序. 输出Hello world runoob@runoob:~$ docker run ubunt ...

  2. 三大框架 之 SSH整合

    目录 SSH整合 Spring整合web项目 在Servlet当中直接加载配置文件,获取对象 存在问题 解决方案 SSH整合 引入Jar包 引入配置文件 创建包结构 创建相关类 创建Customer业 ...

  3. Spring Bean相关配置

    Bean相关配置 1.名称与标识 id 使用了约束中的唯一约束.里面不能出现特殊字符的 name 没有使用约束中的唯一约束.里面可以出现特殊字符. 设置对象的生命周期方法 init-method Be ...

  4. python判断字符串包含关系

    转自---http://blog.csdn.net/yl2isoft/article/details/52079960 1.使用成员操作符 in >>> s='nihao,shiji ...

  5. java.util之一:ArrayList

    ArrayList是java中的线性结构的一种表示方法,在java中使用频率非常高,下面来一步一步分析其底层的实现.(JDK1.8) 一.构造函数 ArrayList的构造函数有三个,分别如下, 我们 ...

  6. 截取完整网页图片的方法 Chrome 浏览器

    截取完整网页图片的方法:https://sspai.com/post/42193 要想使用截图功能,你需要首先确保 Chrome 已升级至 59 或更高版本.在想要截图的网页中,首先按下 ⌘Comma ...

  7. JS构造函数中有return

    function foo(name) { this.name = name; return name } console.log(new foo('光何')) function bar(name) { ...

  8. ping 域名

  9. You are using the runtime-only build of Vue where the template compiler is not available. Either pre

    在升级脚手架到vue-cli3.0版本的时候出现了这个报错: [Vue warn]: You are using the runtime-only build of Vue where the tem ...

  10. Andorid SQLite数据库开发基础教程(2)

    Andorid SQLite数据库开发基础教程(2) 数据库生成方式 数据库的生成有两种方式,一种是使用数据库管理工具生成的数据库,我们将此类数据库称为预设数据库,另一种是使用代码生成的数据库.