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 ...
随机推荐
- Spring Boot搭建Web项目常用功能
搭建WEB项目过程中,哪些点需要注意: 1.技术选型: 前端:freemarker.vue 后端:spring boot.spring mvc 2.如何包装返回统一结构结果数据? 首先要弄清楚为什么要 ...
- git error: RPC failed; result=56, HTTP code = 200
突然发现git pull 后出现几次都无果,百度后, 发现是curl的postBuffer 默认值较小的原因,配置下这个值,就不会出现该错误了.解决如下: git config --global ht ...
- Java_文件夹拷贝
一.思路 * 文件夹的拷贝 1.递归查找子孙级文件 2.文件复制 文件夹创建 二.代码 package com.ahd.File; import java.io.File; import java.i ...
- Java集合类根接口:Collection 和 Map
前言 在前文中我们了解了几种常见的数据结构,这些数据结构有着各自的应用场景,并且被广泛的应用于编程语言中,其中,Java中的集合类就是基于这些数据结构为基础. Java的集合类是一些非常实用的工具类, ...
- 慕课网maven多环境配置
profile 下面的节点,是把profile 标签内容复制几份,并且需要把<activation> 去掉.在idea右侧 maven button 中会出现选择 节点. 接着打包命令和打 ...
- Java学习笔记之——this关键字、非静态成员属性和静态成员属性的区别、类的加载顺序
一.this关键字 1.代表当前类的对象 2.通过” . ”调用成员属性和成员方法 3.通过this可以区分成员属性和参数 参数名和属性名相同的情况,默认是参数名 二.非静态成员属性和静态成员属性的区 ...
- python爬虫scrapy项目详解(关注、持续更新)
python爬虫scrapy项目(一) 爬取目标:腾讯招聘网站(起始url:https://hr.tencent.com/position.php?keywords=&tid=0&st ...
- WORLD 合并多个WORLD中的文本
1,把多个文档放入一个文件夹中. 2,新建一个WORLD文档. 3,点击插入----对象----文件中的文字----选中文件中的多个WORLD文档----打开.
- 常见js面试题
包含内容: Array indexOf(). 数组扁平化 isArray() 数组的去重 Object.is() Array.filter 用一行代码实现数组扁平化? JavaScript isArr ...
- 16-pymysql模块的使用
[转]16-pymysql模块的使用 本节重点: pymysql的下载和使用 execute()之sql注入 增.删.改:conn.commit() 查:fetchone.fetchmany.fetc ...