题解 CF1216A 【Prefixes】
题目大意:给你一个长度为$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】的更多相关文章
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- Codeforces 381 简要题解
做的太糟糕了...第一题看成两人都取最优策略,写了个n^2的dp,还好pre-test良心(感觉TC和CF的pretest还是很靠谱的),让我反复过不去,仔细看题原来是取两边最大的啊!!!前30分钟就 ...
- Shortest Prefixes(trie树唯一标识)
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15948 Accepted: 688 ...
- Codeforces 1092C Prefixes and Suffixes(思维)
题目链接:Prefixes and Suffixes 题意:给定未知字符串长度n,给出2n-2个字符串,其中n-1个为未知字符串的前缀(n-1个字符串长度从1到n-1),另外n-1个为未知字符串的后缀 ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- POJ 2001 Shortest Prefixes 【 trie树(别名字典树)】
Shortest Prefixes Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15574 Accepted: 671 ...
- CoderForces Round526 (A~E)题解
A. The Fair Nut and Elevator time limit per test 1 second memory limit per test 256 megabytes input ...
- codeforces 380A Sereja and Prefixes (递归)
题目: A. Sereja and Prefixes time limit per test 1 second memory limit per test 256 megabytes input st ...
- POJ 2001 Shortest Prefixes (Trie)
题目链接:POJ 2001 Description A prefix of a string is a substring starting at the beginning of the given ...
随机推荐
- HTML中各标签对应的英文意思
HTML中各标签对应的英文意思 一.总结 一句话总结: 结合标签的英语全称,可以更加方便的知道标签的意思 二.HTML中标签对应的英文(方便理解记忆)(转自) 转自:HTML中标签对应的英文(方便理解 ...
- * resolve_conffiles: Existing conffile /etc/config/dhcp is different from the conffile in the new package. The new conffile will be placed at /etc/config/dhcp-opkg.
* resolve_conffiles: Existing conffile /etc/config/dhcp is different from the conffile in the new pa ...
- Communications link failure due to underlying exception: ** BEGIN NESTED EXC
一是将 wait_timeout=31536000 interactive_timeout=31536000 将过期时间修改为1年. 二是在连接URL上添加参数:&autoReconnect= ...
- JQuery事件绑定bind、live、on、trigger
one 作用:只触发一次,并在触发后失效,触发时会产生时间冒泡. 语法:$(selector).one(event,data,function) 例子: $(item).one("click ...
- python : 设计模式之外观模式(Facade Pattern)
#为啥要用外观模式举例说明 这个例子很形象,直接从人家博客上贴过来的,参考链接在下面 不知道大家有没有比较过自己泡茶和去茶馆喝茶的区别,如果是自己泡茶需要自行准备茶叶.茶具和开水,如图1(A)所示,而 ...
- Alternatives to Activiti for all platforms with any license
Activiti Activiti is a light-weight workflow and Business Process Management (BPM) Platform targeted ...
- XSS平台-学习
单点登录 - Telnet 404https://sso.telnet404.com/cas/login?service=https%3A%2F%2Fwww.seebug.org%2Faccounts ...
- [转]java生成 excel 并导出文件
原文:https://blog.csdn.net/xunwei0303/article/details/53213130 目前,比较常用的实现Java导入.导出Excel的技术有两种Jakarta P ...
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第6节 SpringBoot拦截器实战和 Servlet3.0自定义Filter、Listener_24、深入SpringBoot过滤器和Servlet配置过滤器
笔记 1.深入SpringBoot2.x过滤器Filter和使用Servlet3.0配置自定义Filter实战(核心知识) 简介:讲解SpringBoot里面Filter讲解和使用Servle ...
- flex简单参考实例
<!DOCTYPE html> <html> <head> <title></title> <style type="tex ...