C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
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 nice.
A garland is called nice if any two lamps of the same color have distance divisible by three between them. I.e. if the obtained garland is tt, then for each i,ji,j such that ti=tjti=tj should be satisfied |i−j| mod 3=0|i−j| mod 3=0. The value |x||x| means absolute value of xx, the operation x mod yx mod y means remainder of xx when divided by yy.
For example, the following garlands are nice: "RGBRGBRG", "GB", "R", "GRBGRBG", "BRGBRGB". The following garlands are not nice: "RR", "RGBG".
Among all ways to recolor the initial garland to make it nice 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 nice garland from the given one.
In the second line of the output print one string tt of length nn — a nice garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
3
BRB
1
GRB
7
RGBGRBB
3
RGBRGBR 这个是一个思维题,需要我们找找规律,我自己没有找到。,看了题解才会的。
这个对3取模和这里有三个数字有着莫大的联系,它的这个要求,决定了这个排列应该是对这三个数的全排的一个循环,所以这个时候就只要一一比对,找到消耗最小的
就可以了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include <vector>
#include <algorithm>
#include <string>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 100;
char s[maxn];
int main()
{
int n,mark=0;
cin >> n;
cin >> s;
int ans = inf;
int len = strlen(s);
string a[6] = { "RBG","RGB","BRG","BGR","GBR","GRB" };
for(int i=0;i<6;i++)
{
int cnt = 0;
for(int j=0;j<len;j++)
{
if (a[i][j % 3] != s[j]) cnt++;
}
if(cnt<ans)
{
mark = i;
ans = cnt;
}
}
printf("%d\n", ans);
for(int i=0;i<len;i++)
{
printf("%c", a[mark][i % 3]);
}
printf("\n");
return 0;
}
C. Nice Garland Codeforces Round #535 (Div. 3) 思维题的更多相关文章
- 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 ...
- E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题
E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #535 (Div. 3) 题解
Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #552 (Div. 3) A题
题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #535 (Div. 3) 1108C - Nice Garland
#include <bits/stdc++.h> using namespace std; int main() { #ifdef _DEBUG freopen("input.t ...
随机推荐
- Hangfire定时任务设置CronExpression表达式
Cron format helper This utility helps you build Cron expressions easily by choosing job scheduling s ...
- ASP.NET Core入门
一.搭建开发环境 在Windows平台下,开发.NET Core 程序需要安装如下内容: 1. .NET Core runtime 2. Visual Studio 2015 with Update ...
- spring2.0:The server time zone value 'Ãùú±êüñ¼ä' is unrecognized or represents more than one time zone. You must configure either th
提示系统时区出现错误,可以在mysql中执行命令: set global time_zone='+8:00' 或者在数据库驱动的url后加上serverTimezone=UTC参数 jdbc:mysq ...
- 蓝桥杯试题----- 打印大X
打印大X 小明希望用星号拼凑,打印出一个大X,他要求能够控制笔画的宽度和整个字的高度.为了便于比对空格,所有的空白位置都以句点符来代替. 要求输入两个整数m n,表示笔的宽度,X的高度.用空格分开(0 ...
- 【Java每日一题】20170328
20170327问题解析请点击今日问题下方的“[Java每日一题]20170328”查看(问题解析在公众号首发,公众号ID:weknow619) package Mar2017; public cla ...
- redirection in linux
2>&1 # Redirects stderr to stdout. # Error messages get sent to same place as standard output ...
- EF实现增删改查
从来没想到过能在这个上面翻车,感慨自学没有培训来得系统啊,废话不多说 ORM:对象关系映射(Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一 ...
- ButterKnife注解框架详解
Android 懒人注解框架 :https://github.com/JakeWharton/butterknife 前言: 注解,相信很多同学都用到了,对控件进行初始化的时候需要用到 findVie ...
- JNI NDK (AndroidStudio+CMake )实现C C++调用Java代码流程
JNI/NDK Java调用C/C++前言 通过第三篇文章讲解在实际的开发过程中Java层调用C/C++层的处理流程.其实我们在很大的业务里也需要C/C+ +层去调用Java层,这两层之间的相互调用 ...
- 使用fiddler抓包手机请求数据
1.启动Fiddler,打开菜单栏中的 Tools > Fiddler Options,打开“Fiddler Options”对话框. 2.在Fiddler Options”对话框切换到“Con ...