Codeforces Round #738 (Div. 2) B. Mocha and Red and Blue

题目链接:Problem - 1559B - Codeforces

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 nn 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 33, 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 tt (1≤t≤1001≤t≤100) — the number of test cases. Each test case consists of two lines.

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

The second line of each test case contains a string ss with length nn, 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

input

Copy

5
7
?R???BR
7
???R???
1
?
1
B
10
?R??RB??B?

output

Copy

BRRBRBR
BRBRBRB
B
B
BRRBRBBRBR

Note

In the first test case, if the squares are painted "BRRBRBR", the imperfectness is 11 (since squares 22 and 33 have the same color), which is the minimum possible imperfectness.

题意:连续两个相同的字母会增加1点值,要求构造字符串使值尽可能小

思路:如果字符串不全是?,就按照有的值开始前后 构造,只要前面的和后面的不一样就行;

如果全是?就BRBRBR或者RBRBRBRB就可

#include<bits/stdc++.h>
using namespace std;


int main(){
	int t;
	cin >> t;
	int n;
	string s;
	while(t--){
		cin >> n;
		cin >> s;
		int ans = 0;
		for(int i = 0; i < n; i++){
			if(s[i] == 'R' || s[i] == 'B'){
				if(ans == 0){
						for(int l = i - 1; l >= 0; l--){
							if(s[l + 1] == 'R'){
								s[l] = 'B';
							}else{
								s[l] = 'R';
							}
						}
				}
				ans++;
				for(int l = i + 1; l < n; l++){
					if(s[l] != '?'){
						break;
					}
					if(s[l - 1] == 'B'){
						s[l] = 'R';
					}else{
						s[l] = 'B';
					}
				}
			}
		}
		for(int i = 0; i < n; i++){
			if(s[i] == '?'){
				if(i & 1){
					s[i] = 'R';
				}else{
					s[i] = 'B';
				}
			}
		}
		cout << s << endl;
	}
	return 0;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值