CF #738(div2)B. Mocha and Red and Blue(构造)

网友投稿 526 2022-05-30

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

CF #738(div2)B. Mocha and Red and Blue(构造)

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 具有相同的颜色),这是最小可能的缺陷。

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

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

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

#include 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<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【沃土方案--IT系统】黄河创新有限公司IT适配系统
下一篇:ES集群检查常用命令
相关文章