#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif int n;
string s;
cin >> n >> s; vector<int> p();
iota(p.begin(), p.end(), ); string colors = "RGB";
string res = "";
int ans = 1e9; do {
string t;
int cnt = ;
for (int i = ; i < n; ++i) {
t += colors[p[i % ]];
cnt += t[i] != s[i];
}
if (ans > cnt) {
ans = cnt;
res = t;
}
} while (next_permutation(p.begin(), p.end())); cout << ans << endl << res << endl; return ;
}

以上是标准程序,以下是我的程序,相比之下我的程序太复杂了。因为没有用到next_permutation

#include<iostream>
#include<algorithm>
#include<limits.h>
using namespace std;
char c[];
int main(){
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>c[i];
}
int minCnt=INT_MAX;
int cnt=;
int flag;
//RGB
for(int i=;i<n/;i++){
if(c[i*]!='R')
cnt++;
if(c[i*+]!='G')
cnt++;
if(c[i*+]!='B')
cnt++;
}
if(n/*<n){
int i=n/*;
if(c[i]!='R')
cnt++;
if(i+<n){
if(c[i+]!='G')
cnt++;
}
}
if(cnt<minCnt){
minCnt=cnt;
flag=;
} //RBG
cnt=;
for(int i=;i<n/;i++){
if(c[i*]!='R')
cnt++;
if(c[i*+]!='B')
cnt++;
if(c[i*+]!='G')
cnt++;
}
if(n/*<n){
int i=n/*;
if(c[i]!='R')
cnt++;
if(i+<n){
if(c[i+]!='B')
cnt++;
}
}
if(cnt<minCnt){
minCnt=cnt;
flag=;
} //BRG
cnt=;
for(int i=;i<n/;i++){
if(c[i*]!='B')
cnt++;
if(c[i*+]!='R')
cnt++;
if(c[i*+]!='G')
cnt++;
}
if(n/*<n){
int i=n/*;
if(c[i]!='B')
cnt++;
if(i+<n){
if(c[i+]!='R')
cnt++;
}
}
if(cnt<minCnt){
minCnt=cnt;
flag=;
} //BGR
cnt=;
for(int i=;i<n/;i++){
if(c[i*]!='B')
cnt++;
if(c[i*+]!='G')
cnt++;
if(c[i*+]!='R')
cnt++;
}
if(n/*<n){
int i=n/*;
if(c[i]!='B')
cnt++;
if(i+<n){
if(c[i+]!='G')
cnt++;
}
}
if(cnt<minCnt){
minCnt=cnt;
flag=;
} //GBR
cnt=;
for(int i=;i<n/;i++){
if(c[i*]!='G')
cnt++;
if(c[i*+]!='B')
cnt++;
if(c[i*+]!='R')
cnt++;
}
if(n/*<n){
int i=n/*;
if(c[i]!='G')
cnt++;
if(i+<n){
if(c[i+]!='B')
cnt++;
}
}
if(cnt<minCnt){
minCnt=cnt;
flag=;
} //GRB
cnt=;
for(int i=;i<n/;i++){
if(c[i*]!='G')
cnt++;
if(c[i*+]!='R')
cnt++;
if(c[i*+]!='B')
cnt++;
}
if(n/*<n){
int i=n/*;
if(c[i]!='G')
cnt++;
if(i+<n){
if(c[i+]!='R')
cnt++;
}
}
if(cnt<minCnt){
minCnt=cnt;
flag=;
} cout<<minCnt<<endl;
if(flag==){
for(int i=;i<n/;i++){
cout<<"RGB";
}
if(n/*<n){
cout<<"R";
if(n/*+<n)
cout<<"G";
}
}
else if(flag==){
for(int i=;i<n/;i++){
cout<<"RBG";
}
if(n/*<n){
cout<<"R";
if(n/*+<n)
cout<<"B";
}
}
else if(flag==){
for(int i=;i<n/;i++){
cout<<"BRG";
}
if(n/*<n){
cout<<"B";
if(n/*+<n)
cout<<"R";
}
}
else if(flag==){
for(int i=;i<n/;i++){
cout<<"BGR";
}
if(n/*<n){
cout<<"B";
if(n/*+<n)
cout<<"G";
}
}
else if(flag==){
for(int i=;i<n/;i++){
cout<<"GBR";
}
if(n/*<n){
cout<<"G";
if(n/*+<n)
cout<<"B";
}
}
else if(flag==){
for(int i=;i<n/;i++){
cout<<"GRB";
}
if(n/*<n){
cout<<"G";
if(n/*+<n)
cout<<"R";
}
} return ;
}

Codeforces Round #535 (Div. 3) 1108C - Nice Garland的更多相关文章

  1. Codeforces Round #535 (Div. 3) 题解

    Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...

  2. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  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 ...

  4. Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]

    hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...

  5. Codeforces Round #535 (Div. 3) 解题报告

    CF1108A. Two distinct points 做法:模拟 如果两者左端点重合就第二条的左端点++就好,然后输出左端点 #include <bits/stdc++.h> usin ...

  6. Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】

    传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...

  7. Codeforces Round #535(div 3) 简要题解

    Problem A. Two distinct points [题解] 显然 , 当l1不等于r2时 , (l1 , r2)是一组解 否则 , (l1 , l2)是一组合法的解 时间复杂度 : O(1 ...

  8. Codeforces Round #535 (Div. 3)

    E: 题意: 给出n个整数ai和m个区间[li,ri] 你可以选择一些区间,并且将区间内的数字都减一.你要选择一些区间,然后使得改变后的数列中maxbi-minbi的值最大. 题解: 假设我们已经知道 ...

  9. Codeforces Round #535 (Div. 3) F

    F. MST Unification 题目传送门 题意: 给你n个顶点,m条边:保证没有重边,其中存在多个MST(最小生成树), 你可以修改一些边的权值,让其中有且仅有一个最小生成树,求最少操作的边数 ...

随机推荐

  1. scrapy 安装流程和启动

    #Windows平台 1. pip3 install wheel #安装后,便支持通过wheel文件安装软件,wheel文件官网:https://www.lfd.uci.edu/~gohlke/pyt ...

  2. c# sharpsvn 客户端开发测试

    1:没有工作副本,上传时会报错的. 会提示本地目录不是not a working copy   而此中文名称就是工作副本, 本地要与svn服务器公用的一个文件夹. 所以每次要checkout 然后才能 ...

  3. How to update XENTRY Connect C5 software with .iso file

    07.2018 Xentry Mercedes SD Connect c5 software update manual for newbies: Important: If you have XDO ...

  4. Luogu 1169 [ZJOI2007]棋盘制作 - 动态规划+单调栈

    Description 给一个01矩阵, 求出最大的01交错的正方形和最大的01交错的矩阵 Solution 用动态规划求出最大的正方形, 用单调栈求出最大的矩阵. 在这里仅介绍求出最大正方形(求最大 ...

  5. [Robot Framework] 通过SikuliLibrary可以获取到图片,但是点击失效

    执行时,可以看到鼠标已经移动到图片上了,但是点击失效,日志也没有报错 后来发现是windows权限的问题. 通过打开Control Panel->System and Security-> ...

  6. SparkStreaming updateStateByKey 保存记录信息

    )(_+_) ) 查看是否存在,如果存在直接获取 )) ssc.checkpoint() )) //使用updateStateByKey 来更新状态 val stateDstream = wordDs ...

  7. NOIP2017普及组T1题解

    神奇的链接 上面时题目. 其实不得不说,这一题很水,比2015年的第一题水多了. 直接按题目套公式就行了,当然你也可以像我一样化简一下. 直接看代码: #include<cstdio> # ...

  8. 数组方法indexOf & lastIndexOf

    indexOf() 语法:arrayObject.indexOf(searchvalue, startIndex) 功能:从数组的开头(位置0)开始向后查找. 参数:searchvalue:必需,要查 ...

  9. linux 磁盘挂载及查看磁盘

    blkid命令实例 .列出当前系统中所有已挂载文件系统的类型: sudo blkid .显示指定设备 UUID: sudo blkid -s UUID /dev/sda5 .显示所有设备 UUID: ...

  10. 2019.01.23 ural1519 Formula 1(轮廓线dp)

    传送门 轮廓线dpdpdp模板题. 题意简述:给一个放有障碍的网格图,问有多少种方法能使所有非障碍格子都在同一条哈密顿回路上面. 考虑用括号序列的写法来状压这个轮廓线. 用000表示没有插头,111表 ...