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(最小生成树), 你可以修改一些边的权值,让其中有且仅有一个最小生成树,求最少操作的边数 ...
随机推荐
- c#设计模式3抽象工厂模式(Abstract Factory)
#region 坦克系列 abstract class Tank { abstract public void Go(); } /// <summary> /// 越野车 /// < ...
- C# fckeditor浏览服务器和上传目录不一致,看不到上传过的文件
fckeditor在上传标签页面,传过文件后,在浏览服务器那里,看不到之前上传的文件,通过浏览服务器页面上传文件,保存的目录也和上传标签页面上传的不是同一个文件夹. 修改方法如下: 打开fckedit ...
- gulp中pipe的作用和来源
gulp的pipe方法是来自nodejs stream API的,并不是gulp本身源码所定义的. 一.pipe方法的作用 pipe跟他字面意思一样只是一个管道 例如我有一堆文件 var s = gu ...
- hdu 1255(线段树 扫描线) 覆盖的面积
http://acm.hdu.edu.cn/showproblem.php?pid=1255 典型线段树辅助扫描线,顾名思义扫描线就是相当于yy出一条直线从左到右(也可以从上到下)扫描过去,此时先将所 ...
- 事件类型(js)
焦点事件:在页面获得或失去焦点时触发. 与document.hasFocus和document.activeElement属性配合,可以得到用户在页面的行踪. blur:元素失去焦点时触发.这个事件不 ...
- 抽屉效果几大github第三方库
首先感谢董铂然博客园,鄙人收藏学习之用,如有朋友看到.有需要请直接前往董铂然博客园本文, 请点击查看原文 在公司项目新版本方案选择中,对主导航中要使用的抽屉效果进行了调研.主要原因是旧的项目中所用的库 ...
- linux 软件编译问题汇总
1.问题: fatal error: openssl/opensslv.h: No such file or directory 解决: sudo apt-get install libssl-dev ...
- sqli-labs:1-4,基于报错的注入
sqli1: 脚本 # -*- coding: utf-8 -*- """ Created on Sat Mar 23 09:37:14 2019 @author: ke ...
- rapidjson 的封装学习
#pragma once #include "Util.h" #include "rapidjson/writer.h" #include "rapi ...
- Tomcat+Redis+Nginx实现session共享(Windows版)
redis安装:xx nginx安装:xx 步骤: 1.下载tomcat-redis-session-manager相应的jar包,主要有三个: wget https://github.com/dow ...