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 ...
随机推荐
- linux 单引号,双引号,反引号
单引号 目的: 为了保护文字不被转换.除了他本身. 就是说除去单引号外, 在单引号内的所有文字都是原样输出. 1. [root@jszwl161 SP49EP9]# echo '$*><! ...
- shell 备份 source code
1. 利用shell脚本备份源码 首先mkdir创建三个目录 backup存放备份代码,script 存放shell脚本,www存放源码 2.创建文件 3. 编写shell脚本 #!bin/sh b ...
- gulp解决跨域的配置文件
//引入插件 var gulp = require('gulp'); // var Proxy = require('gulp-connect-proxy'); var connect = requi ...
- @RequestParam加与不加的区别
最简单的两种写法,加或不加@RequestParam注解 @RequestMapping("/list") public String test(int userId) { ret ...
- Android项目实战(三十三):AS下获取获取依赖三方的jar文件、aar 转 jar
使用 Android studio 开发项目中,有几种引用三方代码的方式:jar 包 ,类库 ,gradle.build 的compile依赖. 大家会发现github上不少的项目只提供compile ...
- adb连接安卓模拟器
为了在电脑上玩手机游戏,国内推出了很多安卓模拟器,mumu.夜神.itools.海马等等.我们也可以用他们来做安卓开发,相对genymotion或者android studio自带的模拟器而言,国产模 ...
- Android权限之动态权限
安卓系统的权限管理机制从API 23 (也就是Android 6.0 又叫做 Android M,)之后发生了比较大的改变,在一些比较危险的权限上要求必须申请动态权限,即使你在AndroidMainf ...
- CSS回顾(常见问题解决)
一.margin的塌陷解决: BFC (block format context)块级格式化上下文格式 display:inline-block float:left / right overflow ...
- UVA 1152 4 Values whose Sum is 0 (枚举+中途相遇法)(+Java版)(Java手撕快排+二分)
4 Values whose Sum is 0 题目链接:https://cn.vjudge.net/problem/UVA-1152 ——每天在线,欢迎留言谈论. 题目大意: 给定4个n(1< ...
- HDU 1722 Cake (数论 gcd)(Java版)
Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2 . 然后 ...