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(最小生成树), 你可以修改一些边的权值,让其中有且仅有一个最小生成树,求最少操作的边数 ...
随机推荐
- json等序列化模块 异常处理
今日学习内容如下: 1.序列化模块 什么叫序列化——将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 比如,我们在python代码中计算的一个数据需要给另外一段程序使用,那我们怎么给? 现 ...
- Java并发集合(三)-ConcurrentHashMap分析和使用
1 http://ifeve.com/hashmap-concurrenthashmap-%E7%9B%B8%E4%BF%A1%E7%9C%8B%E5%AE%8C%E8%BF%99%E7%AF%87% ...
- 为什么CNN能自动提取图像特征
1.介绍 在大部分传统机器学习场景里,我们先经过特征工程等方法得到特征表示,然后选用一个机器学习算法进行训练.在训练过程中,表示事物的特征是固定的. 后来嘛,后来深度学习就崛起了.深度学习对外推荐自己 ...
- javascript 高级程序设计 四
新的一天开始,让我们伴随者轻快的心情,开始今天的笔记 1.操作符: (1): *./.-在ECMAScript中操作的时候,如果遇到有一个操作值不是数值型(Number),那么就会在后台调用numbe ...
- UI设计初学者必看,这款设计神器教你快速入门
网络时代,网页和手机App已经深入到人们生活的方方面面.这也使得App界面设计越来越受青年求职者们的青睐,并纷纷投入这个行业.但是,作为UI设计初学者,究竟如何才能快速的入门?当今市场上,是否有那么一 ...
- .net利用NPOI生成excel文件
整理代码,这个是生成excel文件,用的是HSSF的方式,只能生成65535行,256列的数据,如果要看office07之后的生成,之前的随笔里提过.这个是一个完整的过程. 首先是已经查找好的数据,这 ...
- 浅谈Spring中的Quartz配置
浅谈Spring中的Quartz配置 2009-06-26 14:04 樊凯 博客园 字号:T | T Quartz是一个强大的企业级任务调度框架,Spring中继承并简化了Quartz,下面就看看在 ...
- 【转载】为什么任何随便输入的账号使用SYSDBA权限都能登陆oracle
其实简单点就是检查一下你的机器有没有一个ora_dba用户组,而且你登陆os的用户是否在这个组里,有的话问题的原因就找到了,下面是转的高手的介绍 本文环境配置:Oracle10gR2,Windows ...
- gcc 库路径里同时有相同文件名的动态库和静态库
找不到库的处理方案 有两种方法: 一.可以把当前路径加入 /etc/ld.so.conf中然后运行ldconfig,或者以当前路径为参数运行ldconfig(要有root权限才行). 二.把当前路径加 ...
- KBMMW 4.84.00 发布
kbmMW is a portable, highly scalable, high end application server and enterprise architecture integr ...