题意:

  就是有一串灯分别颜色是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. virtualbox中 Ubuntu挂载共享文件夹

    1. 进入 /mnt 目录 2. 新建目录 share 3. sudo mount -t vboxsf share /mnt/share(其中的第一个share是共享文件夹的名字) 4. 成功

  2. 学会JavaScript函数式编程(第1部分)

    摘要: JS函数式编程入门. 原文:学会使用函数式编程的程序员(第1部分) 作者:前端小智 Fundebug经授权转载,版权归原作者所有. 在这篇由多部分组成的文章中,接下来将介绍函数式编程的一些概念 ...

  3. laravel compact的用法

    向视图中传递变量 我们在开发web应用当中,通常都不是为了写静态页面而生的,我们需要跟数据打交道,那么这个时候,问题就来了,在一个MVC的框架中,怎么将数据传给视图呢?比如我们要在 ArticleCo ...

  4. agc002E - Candy Piles(博弈论)

    题意 题目链接 Sol Orz SovitPower #include<bits/stdc++.h> #define Pair pair<int, double> #defin ...

  5. MMU学习总结

    待完善 一.MMU主要完成哪些事务? 二.PowerPC上的BAT.LAW是做什么用的? 三.

  6. Navicat Premium for Mac 破解版地址

    找了好几个都不能使用    试了一下这个  可以使用 放地址:http://www.orsoon.com/Mac/85386.html

  7. Python_json数据检索与定位之jsonPath类库

    json数据检索与定位之jsonPath类库   by:授客 QQ:1033553122 实践环境 win7 64 Python 3.4.0 jsonpath_ng-1.4.3-py2.py3-non ...

  8. ubuntu 安装PG10 更新packet 创建超级账号

    ubuntu 安装PG10 更新packet 创建超级账号 安装pg10 我的环境是16.04 server版本 MAC和windows 建议使用安装包 直接官网下载 echo 'deb http:/ ...

  9. 智能POS正餐主副机模式FAQ(无桌台或桌台模块)

    1.无桌台 (1).如果是初次使用,首先检查是否是新建的机器号,新建的机器是默认关闭桌台的,需要到模块管理中开启. 2.无桌台模块 (1).是否在主副机开启连接上后重启主机与副机,且同步数据.

  10. 使用IEDriverServer.exe驱动IE11,实现自动化测试

            +  下载IEDriverServer   http://dl.pconline.com.cn/download/771640-1.html 解压缩得到IEDriverServer.e ...