题意:

  就是有一串灯分别颜色是R,G,B。要求将每种颜色的灯相隔2个不同的灯。比如,RGR变成RGB才叫好看。

分析:

  RGB有6种排列,分别是:"RGB", "RBG", "GBR", "GRB", "BGR", "BRG"。但是注意的是,两种之间的排列,肯定是不满足这样的情况的。

所以,怎样才能满足题目的要求呢?这样只有同样的情况才可以。也就是说RGRBGRRRG每个只能按照一个排列来进行更改。因为,把这样的字符串这样分三个改好后

其实就已经是好看的。也就是6种情况都进行暴力,然后比较大小。


#include<iostream>
#include<string>
using namespace std;
const int maxn = * 1e5 + ;
string ss[] = { "RGB", "RBG", "GBR", "GRB", "BGR", "BRG" };
int vis[];
int main(){
char st[maxn];
int n;
cin >> n;
cin >> st;
for (int j = ; j < ;++j)
for (int i = ; i < n; ++i){
if (st[i] != ss[j][i % ]){ ++vis[j]; }
}
int minn = ;
for (int i = ; i < ; ++i){
if (vis[minn]>vis[i])minn = i;
}
cout << vis[minn] << endl;
for (int i = ; i < n; ++i){
cout << ss[minn][i % ];
}
cout << endl;
}

C. Nice Garland的更多相关文章

  1. POJ 1759 Garland(二分+数学递归+坑精度)

    POJ 1759 Garland  这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...

  2. poj 1759 Garland (二分搜索之其他)

    Description The New Year garland consists of N lamps attached to a common wire that hangs down on th ...

  3. poj 1759 Garland

    Garland Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2365   Accepted: 1007 Descripti ...

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

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

  6. Diverse Garland CodeForces - 1108D (贪心+暴力枚举)

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  7. Nice Garland CodeForces - 1108C (思维+暴力)

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  8. Codeforces 1108D - Diverse Garland - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...

  9. 1.23 codeforces div3 C.Nice Garland

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  10. 758B Blown Garland

    B. Blown Garland time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. Python3 系列之 基础语法篇

    基础数据类型 整数 python 可以处理任意大小的整数 浮点数 python 可以处理任意大小的浮点数,但是需要注意的一点是:整数运算永远是精确的(除法也是精确的),而浮点数运算则可能会有四舍五入的 ...

  2. MySQL添加新用户、为用户创建数据库、为新用户分配权限

    登录MySQL [root@VM_0_2_33_centos /]#mysql -u root -p 添加新用户 允许本地 IP 访问 localhost, 127.0.0.1 mysql>'; ...

  3. CSS3动画属性:动画(animation)

    一:动画(animation)的参数详解 由于上面用到了animation动画,这里详细介绍下这个animation的参数. 简介 CSS动画(Animations)简单说就是在一段固定的动画时间内暗 ...

  4. React 入门学习笔记整理目录

    React 入门学习笔记整理(一)--搭建环境 React 入门学习笔记整理(二)-- JSX简介与语法 React 入门学习笔记整理(三)-- 组件 React 入门学习笔记整理(四)-- 事件 R ...

  5. 【机器学习】Google机器学习工程的43条最佳实践

    https://blog.csdn.net/ChenVast/article/details/81449509 本文档旨在帮助那些掌握机器学习基础知识的人从Google机器学习的最佳实践中获益.它提供 ...

  6. iOS--------获取当前连接的WiFi以及IP地址

    导入头文件 #import <ifaddrs.h>#import <arpa/inet.h>#import <SystemConfiguration/CaptiveNet ...

  7. react-router-dom v^4路由、带参路由的配置

    首先安装路由 npm install --save react-router-dom 新建一个router.js文件 然后我们的router.js代码如下↓ import React from 're ...

  8. 【JS基础】类型转换——不同数据类型比较

    小试牛刀 输出下列数据比较结果 [] == 0; //==============================================================true [] == ...

  9. ES搜索引擎集群模式搭建【Kibana可视化】

    一.简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎(与Solr类似),基于RESTful web接口.Elasticsearch是用Ja ...

  10. mssql sqlserver 模拟for循环的写法

    转自:http://www.maomao365.com/?p=6567 摘要: 下文讲述sql脚本模拟for循环的写法,如下所示: /* for样例 for('初始值','条件','执行后自增') 通 ...