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性能优化2- 依据场景选择技术
1.索引的坏处 索引可以加快查询效率,但是使用不当,会造成插入性能很低 drop table test1 purge; drop table test2 purge; drop table test3 ...
- C#设计模式-2工厂方法模式(Factory Method)
什么是工厂模式?类比生活中的概念,当我们需要打电话的时候,我们需要一部手机,我们通常会选择直接去卖手机的实体店买.但在程序设计中,当我们需要调用一个类(PhoneA或PhoneB)的方法的时候,我们往 ...
- ES6 Reflect的认识
首先我们要了解一下,为什么会新添加这么一个全局对象?如果你看过Reflect的一些函数,你就会发现,这个对象上的方法基本上都可以从Object上面找到,找不到的那些,也是可以通过对对象命令式的操作去实 ...
- ES6 Proxy的应用场景
一.相关API Proxy Reflect 二.Proxy应用场景 1.数据校验 表单提交的时候做数据校验,例如年龄是不是满足条件,数据类型是不是满足要求等等,这场场景非常适合使用Proxy. 下面展 ...
- vs 调试 IE显示“无法显示该网页
在用VS2010调试网站的时候,突然页面不能正常显示了,IE显示“无法显示该网页”.症状一: IE地址栏里面显示的端口号和桌面任务栏右下角“ASP.NET Development Server”的端口 ...
- Java VisualVM 插件地址
打开Java VisualVM检查更新插件时,默认的连接连不上,通过浏览器访问之后发现默认的服务器已经404,新地址已经迁移到github,下面这个地址里面有不同版本jdk对应的插件中心地址. htt ...
- PHP 异步使用swoole的可行性测试
PHP的异步.并行.高性能网络通信引擎swoole框架,在一开始我就比较注意,原因无他,php在swoole未出的情况下在多线程调度上确实算得上没有较好的解决方案. 我以系统的注册流程举例,在比较复杂 ...
- oracle:the password has expired
今天在用dbvisualizer登录数据库的时候,报了the password has expired的错误,于是上网查了一下原因,是因为数据库密码过期了,因为默认的是180天. 解决方法: 1)用系 ...
- 来看看N多设计师笔下的Spider Man
很多电影在大获成功后,其中的人物都成了火热的IP,漫威的各类超级英雄就是个很好的例子,今天突发奇想看看各种漫画人物在插画师手中同一人物会有什么样的不同,所以以蜘蛛侠为主题,搜集了很多插画师笔下的蜘蛛侠 ...
- PS制作纸质复古野外露营插画分享
经常有人说一些复古风,就觉得蛮难,其实制作过程其实没有想象中复杂,从1850年到2017年,通过这160多年里的平面设计,给我们的作品添加上一些新鲜的灵感和活力,本次教程就来教大家用PS做出耐看的纸质 ...