题意:

  就是有一串灯分别颜色是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. Excel通用类工具(二)

    前言 上一篇中写到了用反射来处理类中的不用的属性,但是Excel的列名还得手动输入,这样还是比较麻烦的,今天这篇就利用自定义注解来解决手动传入列名的问题:其实很简单的,只需要在上一篇的基础上加一个类就 ...

  2. Java并发编程-CountDownLatch

    基于AQS的前世今生,来学习并发工具类CountDownLatch.本文将从CountDownLatch的应用场景.源码原理解析来学习这个并发工具类. 1. 应用场景 CountDownLatch是并 ...

  3. 7个拒绝使用TypeScript的借口

    译者按: TypeScript 学习成本不高,项目切换成本不低,不过还是值得试一试的! 原文:7 bad excuses for not using TypeScript 译者: Fundebug 为 ...

  4. 如何通过setTimeout理解JS运行机制详解

    setTimeout()函数:用来指定某个函数或某段代码在多少毫秒之后执行.它返回一个整数,表示定时器timer的编号,可以用来取消该定时器. 例子 ? 1 2 3 4 5 console.log(1 ...

  5. 【代码笔记】Web-JavaScript-JavaScript错误

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  6. 如何用ABP框架快速完成项目(9) - 用ABP一个人快速完成项目(5) - 不要执着于设计模式和DDD理论,避免原教旨主义

    为什么要写这节文章呢?   首先主动看我这系列文章和参加活动课程的同学, 肯定是积极好学的. 所以很大概率是学过设计模式和DDD理论的. 很大概率不是走一点都不懂设计模式和DDD理论这个极端, 而是走 ...

  7. JMeter 监听器之保存响应到文件

    监听器之保存响应到文件   by:授客 QQ:1033553122 测试环境 apache-jmeter-2.13 1. 保存结果到响应文件 说明: 文件名称前缀:设置响应文件所在路径(路径必须已存在 ...

  8. 深入理解Java虚拟机02--Java内存区域与内存溢出异常

    一.概述 我们在进行 Java 开发的时候,很少关心 Java 的内存分配等等,因为这些活都让 JVM 给我们做了.不仅自动给我们分配内存,还有自动的回收无需再占用的内存空间,以腾出内存供其他人使用. ...

  9. JSON基础知识点

    一.介绍: JSON是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成. 二.数据格式: 1.JSON建构于两种数据格式: “名称/值”对(键值对)的集合,不同的语言中,它被理解为 ...

  10. NPOI 笔记

    前言 文档:http://npoi.codeplex.com/documentation 示例:https://npoi.svn.codeplex.com/svn/ 下载:https://www.nu ...