D. Diverse Garland-----CF字符串
1 second
256 megabytes
standard input
standard output
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 11) have distinct colors.
In other words, if the obtained garland is tt then for each ii from 11 to n−1n−1 the condition ti≠ti+1ti≠ti+1 should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of lamps.
The second line of the input contains the string ss consisting of nn characters 'R', 'G' and 'B' — colors of lamps in the garland.
In the first line of the output print one integer rr — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string tt of length nn — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
9
RBGRRBRGG
2
RBGRGBRGR
8
BBBGBRRR
2
BRBGBRGR
13
BBRRRRGGGGGRR
6
BGRBRBGBGBGRG
#include<iostream>
#include<stdio.h>
#include<string.h>
#define maxn 100000000
char str[maxn];
int n ,ans=;
using namespace std;
int main()
{
cin>>n>>str;
for(int i=;i<n-;i++)
{
if(str[i]==str[i+])
{
if(str[i]!='R'&&str[i+]!='R')
str[i+]='R';
else if(str[i]!='G'&&str[i+]!='G')
str[i+]='G';
else if(str[i]!='B'&&str[i+]!='B')
str[i+]='B';
ans++; }
}
cout<<ans<<endl;
for(int i=;i<n;i++)
cout<<str[i];
cout<<endl;
return ; }
D. Diverse Garland-----CF字符串的更多相关文章
- Diverse Garland CodeForces - 1108D (贪心+暴力枚举)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 1108D - Diverse Garland - [简单DP]
题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...
- D. Diverse Garland
题意:灯有三种颜色R,G,B.只要同一种颜色相邻就不可以.问最少需要换几次,可以使在一串灯中没有相邻灯的颜色相同. 思路:贪心思路:我们知道一个程序都是要子阶段,然后子阶段各个组合起来形成这个程序.那 ...
- CF刷刷水题找自信1
CF 1108A Two distinct points 题目意思:给你两个线段的起点和终点,让你给出两个不同的点,这两点分别处于两个不同的线段之中.解题思路:题目说如果存在多种可能的点,随意一组答案 ...
- 第9周cf刷题(dp)
Problems(1300-1600) an ac a day keeps the doctor away Gas Pipeline (1500) 2019.10.28 题意: 管道工人需要在一段凹凸 ...
- Codeforces-D-Diverse Garland(思维)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]
hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...
- Codeforces Round #535 (Div. 3) 题解
Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...
随机推荐
- Luogu 4091 [HEOI2016/TJOI2016]求和
BZOJ 4555 一道模板题. 第二类斯特林数有公式: $$S(n, m) = \frac{1}{m!}\sum_{i = 0}^{m}(-1)^i\binom{m}{i}(m - i)^n$$ 考 ...
- Mr_matcher的细节2
1.参数服务器 ROS参数服务器能保存数据类型包括:strings, integers, floats, booleans, lists, dictionaries, iso8601 dates, a ...
- 在IE中检查控件是否安装成功
步骤: 1.打开图片上传页面 2.打开IE加载项 3.在加载项中可以看到加载的控件 4.点击详细信息,查看文件名称和文件位置
- Linux 查看是64位还是32位
[root@VM_7_88_centos ~]# uname -a Linux VM_7_88_centos 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36: ...
- jqGrid查询案例(实用)
var ThisTime = getNowFormatDate(); //加载表格 function GetGrid() { var selectedRowIndex = 0; var $gridTa ...
- FTP无法获取目录及文件
在防火墙打开的情况下 如果不能获取,尝试将C:\windows\system32\svchost.exe 加入防火墙允许通道中. 并且设置为 主动模式
- Ubuntu下vi编辑器不听话
编辑文件/etc/vim/vimrc.tiny,将“compatible”改成“nocompatible”非兼容模式: 并添加一句:set backspace=2
- php复制目录
function copyDir($dirSrc,$dirTo) { if(is_file($dirTo)) { echo '目标不是目录不能创建!'; return; } if(!file_exis ...
- windows下go调用内存dll
有时候我们希望将dll嵌入到程序内部,以提高程序的安全性,这里我写的一个开源memorydll模块. 首先 go get github.com/nkbai/go-memorydll 然后在需要的时候 ...
- Oracle下载及安装
Oracle 下载及安装 一.官方下地址: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/in ...