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 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...
随机推荐
- 28. LAST() 函数
LAST() 函数 LAST() 函数返回指定的字段中最后一个记录的值. 提示:可使用 ORDER BY 语句对记录进行排序. SQL LAST() 语法 SELECT LAST(column_nam ...
- 【linux命令】setterm控制终端属性命令(中英文)
[linux命令]setterm控制终端属性命令(中英文) 2018年03月23日 17:13:44 阅读数:489 标签: linux 更多 个人分类: linux 摘自:https://blog. ...
- AutoLayout自动布局,NSLayoutConstraint 视图约束使用
一.方法 NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:<#(id)#> attribut ...
- 编写高质量代码改善C#程序的157个建议——建议1:正确操作字符串
最近拜读了陆敏技老师的<编写高质量代码改善C#程序的157个建议>,感觉不错,决定把笔记整理一遍. 建议1: 正确操作字符串 字符串应该是所有编程语言中使用最频繁的一种基础数据类型.如果使 ...
- vmware10安装Arch
必须保证机器能够上网! 1.vmware10中创建虚拟机(跟虚拟机中安装其他系统同样的操作). 2.开启上一步中创建的虚拟机. 3选择第一项进入 4自动进入root命令行 5进入 /dev (进行分区 ...
- nagios+influxdb+grafana的监控数据可视化流程
nagios介绍 nagios是一款开源监控的应用,可用于监控本地和远程主机的日志.资源.死活等等诸多功能.通过snmp协议和nrpe协议. nagios的配置文件是由nconf上进行配置,然后点击生 ...
- sqlite数据库文件查看
- NSUserDefaults数据存储
前言 用来保存应用程序设置和属性.用户保存的数据.用户再次打开程序或开机后这些数据仍然存在. 如果往 userDefaults 里存了一个可变数组,取出来的时候这个数组对象就变成了不可变的. NSUs ...
- javaee--学生成绩录入与显示--Struts2标签的使用
类Score.java:各课程的成绩及平均成绩 类Student.java:学生姓名.学号及Score类 类ScoreAction.java:将Student类存在一个List对象中, execute ...
- Atcoder Grand Contest 031B(DP,思维)
#include<bits/stdc++.h>using namespace std;int a[200007];int b[200007];long long dp[200007];lo ...