Codeforces Round #535 (Div. 3) 1108C - Nice Garland
#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的更多相关文章
- Codeforces Round #535 (Div. 3) 题解
Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...
- 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 ...
- 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 Round #535 (Div. 3) [codeforces div3 难度测评]
hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...
- Codeforces Round #535 (Div. 3) 解题报告
CF1108A. Two distinct points 做法:模拟 如果两者左端点重合就第二条的左端点++就好,然后输出左端点 #include <bits/stdc++.h> usin ...
- 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 ...
- Codeforces Round #535(div 3) 简要题解
Problem A. Two distinct points [题解] 显然 , 当l1不等于r2时 , (l1 , r2)是一组解 否则 , (l1 , l2)是一组合法的解 时间复杂度 : O(1 ...
- Codeforces Round #535 (Div. 3)
E: 题意: 给出n个整数ai和m个区间[li,ri] 你可以选择一些区间,并且将区间内的数字都减一.你要选择一些区间,然后使得改变后的数列中maxbi-minbi的值最大. 题解: 假设我们已经知道 ...
- Codeforces Round #535 (Div. 3) F
F. MST Unification 题目传送门 题意: 给你n个顶点,m条边:保证没有重边,其中存在多个MST(最小生成树), 你可以修改一些边的权值,让其中有且仅有一个最小生成树,求最少操作的边数 ...
随机推荐
- Oracle存储过程in、out、in out 模式参数
Oracle存储过程in.out.in out 模式参数 标签: oracle存储inout参数 2016-11-14 11:59 3272人阅读 评论(0) 收藏 举报 分类: oracle(7) ...
- andorid 列表视图之SimpleAdapter
.xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android=&qu ...
- Thrift.0
0. Thrift的特性 1. 安装Thrift编译器 [Todo] http://thrift.apache.org/docs/install/ http://thrift.apache.org/d ...
- HDOJ2089 不要62
原题链接 数位\(DP\)入门题. 记录前一个枚举到的数位,在每次枚举的时候避开\(4\),如果前一个数位为\(6\),还要跳过\(2\). 然后套上记搜模板就好. #include<cstdi ...
- tp5查看版本
5.0 base.php 5.1 echo \think\facade\App::version();//用这行代码查看版本
- Python之路(第九篇)Python文件操作
一.文件的操作 文件句柄 = open('文件路径+文件名', '模式') 例子 f = open("test.txt","r",encoding = “utf ...
- 通过代理上网时,qq等应用程序连网出错
虽然现在基本上都用无线,有线宽带等,但是有时候还是避免不了通过代理上网时,于是就发生浏览器可以正常浏览网页,qq等应用程序连接出错等问题,上网搜了好长时间, 都没解决问题,后来慢慢琢磨(其实是乱 ...
- ERROR - abandon connection, open stackTrace
项目采用的是阿里巴巴的druid连接池,配置文件中有个removeAbandoned的配置(意义是某个连接如果超过设置的连接活动时间的话,连接会被强制关掉),但是因为爬虫中某些连接会长时间处于活动状态 ...
- Maven中maven-source-plugin,maven-javadoc-plugin插件的使用
摘要:今天领导说要把项目通过maven生产源码包和文档包并发布到自己的私服上,经过查看mavne官网发现有两个maven插件可以做到这些工作,一个是maven-source-plugin,另一个是ma ...
- 使用policheck 检测
Policheck is a profing and testing tool for sensitive terminology and helps in ensuring thattrustwor ...