C. Nice Garland
题意:
就是有一串灯分别颜色是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的更多相关文章
- POJ 1759 Garland(二分+数学递归+坑精度)
POJ 1759 Garland 这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...
- poj 1759 Garland (二分搜索之其他)
Description The New Year garland consists of N lamps attached to a common wire that hangs down on th ...
- poj 1759 Garland
Garland Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2365 Accepted: 1007 Descripti ...
- 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 ...
- Diverse Garland CodeForces - 1108D (贪心+暴力枚举)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- Nice Garland CodeForces - 1108C (思维+暴力)
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- Codeforces 1108D - Diverse Garland - [简单DP]
题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...
- 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 ...
- 758B Blown Garland
B. Blown Garland time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- Python面试题之Python面试题汇总
在这篇文章中: Python基础篇 1:为什么学习Python 2:通过什么途径学习Python 3:谈谈对Python和其他语言的区别 Python的优势: 4:简述解释型和编译型编程语言 5:Py ...
- 3;XHTML排列清单控制标记
1.无序号条例式清单<ul> 2.有序号条例式清单<ol> 3.无序列表和有序列表的结合应用 4.叙述式清单<dl> 排列清单控制标记可以创建一般的列表.编号列表或 ...
- ASPxGridView 添加勾选列--全选 和 后端获取勾的行ID
一.HTML 代码 <table style="width: 100%;"> <tr> <td> <asp:Button ID=" ...
- Locust 安装
环境:CentOS 7.4,python2.7.5 # 安装 pip yum -y install python-pip # 安装 locustio pip install locustio mkdi ...
- @RequestParam加与不加的区别
最简单的两种写法,加或不加@RequestParam注解 @RequestMapping("/list") public String test(int userId) { ret ...
- Android 滑动定位+吸附悬停效果实现
在前两篇文章中,分别介绍了tablayout+scrollview 和 tablayout+recyclerview 实现的滑动定位的功能,文章链接: Android 实现锚点定位 Android t ...
- 操作系统-进程通信(信号量、匿名管道、命名管道、Socket)
进程通信(信号量.匿名管道.命名管道.Socket) 具体的概念就没必要说了,参考以下链接. 信号量 匿名管道 命名管道 Socket Source Code: 1. 信号量(生产者消费者问题) #i ...
- git 入门教程之初识git
初识 git git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. 背景 我们都知道,Linus 在1991年创建了开源的linux系统,随着不断发展壮大,目前已发展成为最大 ...
- IT真的是万能的吗?
朋友最近郁闷了,作为企业信息化主管的他最近经常听到的一句话就是:IT是万能的,不能拒绝用户的任何需求.这句话如果是普通用户私下开玩笑说说也就罢了,但现在演变成了老板在会议场合不止一次这么说,那就让人匪 ...
- java中带图片按钮的大小设置
在java部分需要用到图形界面编程的项目中,经常会使用图片设置对按钮进行美化,但是使用时会出现一个很麻烦的问题,那就是按钮的大小默认按照图片的大小来显示,这大大降低了界面的美观程度: 按照方法: JB ...