Codeforces Round #587 (Div. 3) A. Prefixes
链接:
https://codeforces.com/contest/1216/problem/A
题意:
Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n.
He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arbitrary number of times (possibly, zero): choose some position in his string and replace the letter on this position with the other letter (i.e. replace 'a' with 'b' or replace 'b' with 'a'). Nikolay can use no letters except 'a' and 'b'.
The prefix of string s of length l (1≤l≤n) is a string s[1..l].
For example, for the string s="abba" there are two prefixes of the even length. The first is s[1…2]="ab" and the second s[1…4]="abba". Both of them have the same number of 'a' and 'b'.
Your task is to calculate the minimum number of operations Nikolay has to perform with the string s to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'.
思路:
从开头开始每两个字符需要不同, 搞一下就行了.
代码:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10;
int n;
char s[MAXN];
int main()
{
cin >> n;
cin >> s;
int op = 0, a = 0, b = 0;
for (int i = 0;i < n;i+=2)
{
if (s[i] != s[i+1])
continue;
if (s[i] == 'a')
s[i] = 'b';
else
s[i] = 'a';
op++;
}
cout << op << endl;
cout << s << endl;
return 0;
}
Codeforces Round #587 (Div. 3) A. Prefixes的更多相关文章
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes
D. Prefixes and Suffixes You have a string s = s ...
- Codeforces Round #587 (Div. 3)
https://codeforces.com/contest/1216/problem/A A. Prefixes 题意大概就是每个偶数位置前面的ab数目要相等,很水,被自己坑了 1是没看见要输出修改 ...
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes(后缀数组orKMP)
D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #587 (Div. 3) D. Swords
链接: https://codeforces.com/contest/1216/problem/D 题意: There were n types of swords in the theater ba ...
- Codeforces Round #587 (Div. 3) C. White Sheet
链接: https://codeforces.com/contest/1216/problem/C 题意: There is a white sheet of paper lying on a rec ...
- Codeforces Round #587 (Div. 3) B. Shooting(贪心)
链接: https://codeforces.com/contest/1216/problem/B 题意: Recently Vasya decided to improve his pistol s ...
- Codeforces Round #587 (Div. 3) F. Wi-Fi(单调队列优化DP)
题目:https://codeforces.com/contest/1216/problem/F 题意:一排有n个位置,我要让所有点都能联网,我有两种方式联网,第一种,我直接让当前点联网,花费为i,第 ...
- Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes
题目链接 题意:给你一个长度n,还有2*n-2个字符串,长度相同的字符串一个数前缀一个是后缀,让你把每个串标一下是前缀还是后缀,输出任意解即可. 思路;因为不知道前缀还是后缀所以只能搜,但可以肯定的是 ...
- Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}
C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle ...
随机推荐
- Date、DateFormat和Calendar类的简单认识
第三阶段 JAVA常见对象的学习 Date.DateFormat和Calendar类的简单认识 Date类 Date:表示特定的瞬间,精确到毫秒. (一) 构造方法: Date():根据当前的默认毫秒 ...
- HanLP封装为web services服务的过程介绍
前几天的召开的2019年大数据生态产业大会不知道大家关注到没有,看到消息是hanlp2.0版本发布了.不知道hanlp2.0版本又将带来哪些新的变化?准备近期看能够拿到一些hanlp2.0的资料,如果 ...
- 什么是DataV数据可视化
DataV数据可视化是使用可视化大屏的方式来分析并展示庞杂数据的产品.DataV旨让更多的人看到数据可视化的魅力,帮助非专业的工程师通过图形化的界面轻松搭建专业水准的可视化应用,满足您会议展览.业务监 ...
- Hello TypeScript
⒈TypeScript简介 1.JavaScript的超集 2.支持ECMAScript6标准,并支持输出ECMAScript3/5/6标准的纯JavaScript代码 3.支持ECMAScript未 ...
- 网络流+最小生成树的最少割边数--How Many to Be Happy?
题意:https://blog.csdn.net/Ratina/article/details/95200594 思路: 首先我们知道最小生成树就是按长度枚举边,能连就连. 那么,如果这条边在最小生成 ...
- DFA与动态规划
1.牛客练习赛45 A 给定字符串, 求字符不相邻的"QAQ"子序列个数. $dp[i][0]$ 只匹配一个'Q'的方案数的前缀和. $dp[i][1]$ 只匹配"QA& ...
- dl in image process
deep learning目前为止无论在分类还是检测上,都是整体的处理,而不会出现像sift这样的局部特征,这个问题或许如果能克服掉,能让检测效果更进一大步.
- Linux环境下安装Nginx及其使用
https://www.jb51.net/article/136161.htm 一.查看CentOS的版本 ? 1 cat /etc/redhat-release 二.添加资源库 在 CentOS 系 ...
- 在开源UOJ的导航栏中添加新页面链接
前言 刚用开源UOJ搭建OJ成功时就想在导航栏那里添加一个站内页面链接,无奈当时乱搞水平低,网上也没有教程,不晓得怎么弄 今天突然来了闲情乱搞一通,结果还真乱搞成了...特意写下为后来人少走点弯路 前 ...
- vue添加图片
首先开始创建一个 static 文件夹用来保存图片 去 setting 里面进行配置 MEDIA_ROOT = os.path.join(BASE_DIR,'media') #前面大写的是死格式,尽量 ...