problem

B. Mocha and Red and Blue
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
As their story unravels, a timeless tale is told once again…

Shirahime, a friend of Mocha’s, is keen on playing the music game Arcaea and sharing Mocha interesting puzzles to solve. This day, Shirahime comes up with a new simple puzzle and wants Mocha to solve them. However, these puzzles are too easy for Mocha to solve, so she wants you to solve them and tell her the answers. The puzzles are described as follow.

There are n squares arranged in a row, and each of them can be painted either red or blue.

Among these squares, some of them have been painted already, and the others are blank. You can decide which color to paint on each blank square.

Some pairs of adjacent squares may have the same color, which is imperfect. We define the imperfectness as the number of pairs of adjacent squares that share the same color.

For example, the imperfectness of “BRRRBBR” is 3, with “BB” occurred once and “RR” occurred twice.

Your goal is to minimize the imperfectness and print out the colors of the squares after painting.

Input
Each test contains multiple test cases.

The first line contains a single integer t (1≤t≤100) — the number of test cases. Each test case consists of two lines.

The first line of each test case contains an integer n (1≤n≤100) — the length of the squares row.

The second line of each test case contains a string s with length n, containing characters ‘B’, ‘R’ and ‘?’. Here ‘B’ stands for a blue square, ‘R’ for a red square, and ‘?’ for a blank square.

Output
For each test case, print a line with a string only containing ‘B’ and ‘R’, the colors of the squares after painting, which imperfectness is minimized. If there are multiple solutions, print any of them.

Example
inputCopy
5
7
?R???BR
7
???R???
1
?
1
B
10
?R??RB??B?
outputCopy
BRRBRBR
BRBRBRB
B
B
BRRBRBBRBR
Note
In the first test case, if the squares are painted “BRRBRBR”, the imperfectness is 1 (since squares 2 and 3 have the same color), which is the minimum possible imperfectness.

B. 摩卡和红蓝
每次测试的时间限制1秒
每个测试的内存限制 256 兆字节
输入标准输入
输出标准输出
随着他们的故事解开,一个永恒的故事再次被讲述…

摩卡的朋友白姬热衷于玩音乐游戏Arcaea并分享摩卡有趣的谜题来解决。这一天,白姬想出了一个新的简单谜题,并希望摩卡能够解决它们。然而,这些谜题对于摩卡来说太容易解决了,所以她希望你解决它们并告诉她答案。谜题描述如下。

有n个正方形排成一排,每个正方形都可以涂成红色或蓝色。

在这些方格中,有的已经画好了,有的则是空白的。您可以决定在每个空白方块上绘制哪种颜色。

一些相邻的方块可能具有相同的颜色,这是不完美的。我们将缺陷定义为共享相同颜色的相邻方块对的数量。

例如,“BRRRBBR”的不完美度为3,“BB”出现一次,“RR”出现两次。

你的目标是尽量减少不完美,并在绘画后打印出正方形的颜色。

输入
每个测试包含多个测试用例。

第一行包含一个整数 t (1≤t≤100)——测试用例的数量。每个测试用例由两行组成。

每个测试用例的第一行包含一个整数 n (1≤n≤100)——正方形行的长度。

每个测试用例的第二行包含一个长度为 n 的字符串 s,包含字符 ‘B’、‘R’ 和 ‘?’。这里’B’代表蓝色方块,‘R’代表红色方块,’?'为一个空白方块。

输出
对于每个测试用例,打印一行只包含 ‘B’ 和 ‘R’ 的字符串,即绘制后正方形的颜色,将缺陷最小化。如果有多个解决方案,请打印其中任何一个。

例子
输入副本
5
7
?R???BR
7
???R???
1
?
1

10
?R??RB??B?
输出副本
BRRBRBR
BRRBRBRB


BRRBRBBRBR
笔记
在第一个测试案例中,如果方块被涂成“BRRBRBR”,则缺陷为 1(因为方块 2 和 3 具有相同的颜色),这是最小可能的缺陷。

solution

对于最长的“ ? ”,它优化了“ RBRB… ”或“ BRBR… ”的涂色,所以它所做的不完美仅与它两侧的颜色有关。

为每个最长的“ ? ”周期选择不完美的一个○ ( n ) 是可以接受的。

更优雅的是,如果“ ? ”左边或右边的方块是画的,只需用与它不同的颜色画“ ? ”。这可以通过考虑奇偶性来证明达到最小缺陷。

#include<bits/stdc++.h>
typedef long long LL;
using namespace std;int main(){ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int T;  cin>>T;while(T--){int n;  cin>>n;string s;  cin>>s;for(int i = 1; i < n; i++){if(s[i]=='?'){if(s[i-1]=='B')s[i]='R';if(s[i-1]=='R')s[i]='B';}}for(int i = n-2; i>=0; i--){if(s[i]=='?'){if(s[i+1]=='B')s[i]='R';if(s[i+1]=='R')s[i]='B';}}if(s[0]=='?'){for(int i = 0; i < n; i++){if(i%2==0)cout<<"B";else cout<<"R";}cout<<"\n";continue;}cout<<s<<"\n";}return 0;
}

CF #738(div2)B. Mocha and Red and Blue(构造)相关推荐

  1. Mocha and Red and Blue 模拟字符串

    题意 : 由'?' 'B' 'R'组成的字符串,将所有'?'变成'B'或者'R',要求出现'BB'和'RR'数量最少,求最终字符串. 思路 : 找到第一个不是'?'的字符(这里有一个注意点,全是'?' ...

  2. AC日记——Red and Blue Balls codeforces 399b

    399B - Red and Blue Balls 思路: 惊讶的发现,所有的蓝球的消除都是独立的: 对于在栈中深度为i的蓝球消除需要2^i次操作: 代码: #include <cstdio&g ...

  3. B. Red and Blue

    time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standa ...

  4. CF 400 div2

    从昨天周赛开始,要耍CF了~ 开始还害怕个人赛自己数论压根不会怎么办,发现CF全是乱搞的题orz 但是就算是乱搞的也不能1A  T^T 犯的错误基本上都是没有把情况归类导致要么是情况想少了,要么是细节 ...

  5. CF #673 div2 赛后总结

    文章目录 前言 A B C D E F 前言 完成成就:在学校熬夜熬到1点 第一次CF打比赛就炸成这个样子 A 题目翻译: 一个长度为 n n n的数组,每次选择 i , j ( 1 ≤ i , j ...

  6. 【CF#468 div2 D. 】Peculiar apple-tree(思维)

    题干: In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiar ...

  7. cf#644 div2 B. Boboniu Plays Chess

    惯例,粘个生草翻译 这题比第一题还简单(简单多了 ) 虽然题面不短,但仔细读就会发现条件不多 刚开始我误以为是一笔画的题,但题中的棋子不同,他是車 ,棋子可以直接跳过一个点,也就是上下左右随便走,那就 ...

  8. CF 868 div2 A—C

    A 题就是一个预处理然后进行枚举 首先数据范围不是很大 然后我们依照题意看看如何构造出对应的要求,也就是说我们需要在不同的下标下使得 ai*aj=1 那么只有1 1 或者-1 -1 那么这个不管是1 ...

  9. 【CF #781 Div2】A-C

    A. GCD vs LCM 题目 分析 给一个数n,使满足条件: a+b+c+d=n,ab的最大公因数为,cd的最小公倍数. b,c,d值都为1,最大公因数及最小公倍数都为1,a=n-3 代码 #in ...

最新文章

  1. numpy.where用法
  2. A+B/A*B求A和B
  3. 鼠标马赛克图像部分区域
  4. C语言 编写程序:请将Fibonacci数列前30项中的偶数值找出来,存储到一维数组中。其中,Fibonacci数列如下:1,1,2,3,5,8,13,21,34...该数列除前两项之外,其他任意
  5. MySQL修改和删除触发器(DROP TRIGGER)
  6. VS11在Win8上的Metro应用
  7. 常用机器学习算法汇总(中)
  8. Polynomial(HDU-6668)
  9. 面试题46. 把数字翻译成字符串
  10. poj1324Holedox Moving搜索
  11. 「leetcode」454.四数相加II:其实需要哈希的地方都能找到map的身影
  12. Axure教程-新手入门基础(小白强烈推荐!!!)
  13. 溢出植入型木马(后门)的原型实现 作者:FLASHSKY(原创)
  14. Modis数据下载及后处理
  15. 基于ssm汽车4s店维修保养试驾服务管理系统 java毕设项目介绍
  16. android中如何如何让dailog横屏显示
  17. Python开源Devops定时任务管理系统(含定时调用接口、定时ssh远程执行命令)
  18. LOL服务器人数最新,英雄联盟大区人数排名
  19. 图像风格迁移cvpr2020_浅谈风格迁移(二)任意风格迁移
  20. 《番茄todo》APP广告的设计与制作

热门文章

  1. 【物理】概念的理解 —— Phase(相位)
  2. 子网掩码(subnet mask)与默认网关(default gateway)
  3. GDB 使用教程(二)
  4. URL vs URI
  5. 数字转换星期几python_Python基本时间转换
  6. python 制作抽奖箱_丽水本地抽奖箱制作公司,抽奖箱制作-优质服务!
  7. python采集文章_用python采集文章保存到wordpress
  8. 如何系统的自学python-如何系统的学习python?
  9. python从入门到放弃百度云-Python从入门到放弃:概论
  10. JavaScript var语句简析