summary:
大概意思是有n盏灯,灯有3种颜色:G/B/R,问最少改多少盏灯的颜色可以使全部相邻的灯颜色不一样并输出更改后的灯盏的颜色序列,任意解。
transmission:
https://codeforces.com/contest/1108/problem/D
啰嗦的problem:
D. Diverse Garland
time limit per test:1 second
memory limit per test:256 megabytes
inputstandard input
outputstandard output
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is si (‘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 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n−1 the condition ti≠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.
Input
The first line of the input contains one integer n (1≤n≤2⋅105) — the number of lamps.
The second line of the input contains the string s consisting of n characters ‘R’, ‘G’ and ‘B’ — colors of lamps in the garland.
Output
In the first line of the output print one integer r — 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 t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
Examples
input
9
RBGRRBRGG
output
2
RBGRGBRGR
input
8
BBBGBRRR
outputCopy
2
BRBGBRGR
input
13
BBRRRRGGGGGRR
output
6
BGRBRBGBGBGRG
solution:
每两个连续的相同颜色灯盏必换一次色,那就换第偶数个同颜色灯盏的色。
要换色的个数全部想加就ok啦。
然后要记得对比旁边两个色然后换颜色,最后输出。
code:
#include<iostream>
#include<cst
ring>
using namespace std;
int main(void)
{
int n;cin >> n;
char a[200005]