B. Mocha and Red and Blue(codeforces#738(Div2)

简介: B. Mocha and Red and Blue(codeforces#738(Div2)

B. Mocha and Red and Blue


time limit per test


1 second


memory limit per test


256 megabytes


input


standard input


output


standard 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 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.


题目我们分析,就是间隔排序,为最优解。


具体实现看代码;


#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
typedef long long ll;
int a[maxn],b[maxn];
string s;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cin>>s;
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='?')
                cnt++;
        }
        if(cnt==n)
        {
            while(n--)
            {
                if(n&1)
                    cout<<"R";
                else
                    cout<<"B";
            }cout<<endl;
            continue;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(j+1<n)
                {
                    if(s[j]=='?'&&s[j+1]=='R')
                    {
                        s[j]='B';
                        break;
                    }
                    if(s[j]=='?'&&s[j+1]=='B')
                    {
                        s[j]='R';
                        break;
                    }
                }
               if(j-1>=0)
               {
                   if(s[j]=='?'&&s[j-1]=='R')
                   {
                       s[j]='B';
                       break;
                   }
                   if(s[j]=='?'&&s[j-1]=='B')
                   {
                       s[j]='R';
                       break;
                   }
               }
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


相关文章
|
数据采集 机器学习/深度学习 搜索推荐
探索数据之海——网络爬虫与数据抓取技术的应用与发展
在当今信息爆炸的时代,获取大量高质量的数据成为各行各业的迫切需求。网络爬虫和数据抓取技术作为一种有效的手段,正在被广泛应用于各个领域。本文将深入探讨网络爬虫的原理、应用场景以及未来的发展趋势,为读者带来关于数据抓取技术的全面了解。
926 5
|
算法 Java 开发工具
Magisk模块:Audio HeadQuarter(使用前仔细阅读)
Magisk模块:Audio HeadQuarter(使用前仔细阅读)
1521 0
|
存储 Shell 编译器
多人协作使用git如何解决冲突?
多人协作使用git如何解决冲突?
366 0
|
机器学习/深度学习 存储 自然语言处理
# 【推荐系统】:协同过滤和基于内容过滤概述
# 【推荐系统】:协同过滤和基于内容过滤概述
# 【推荐系统】:协同过滤和基于内容过滤概述
|
机器学习/深度学习 传感器 算法
基于力学分析的系泊系统设计附matlab代码
基于力学分析的系泊系统设计附matlab代码
|
资源调度 JavaScript 前端开发
【TypeScript】TS类型声明文件
【TypeScript】TS类型声明文件
433 0
|
Web App开发
selenium 使用本地浏览器插件
selenium 使用本地浏览器插件
|
存储 JavaScript 数据库
第2章 关系数据库——2.1关系数据结构及形式化定义
第2章 关系数据库——2.1关系数据结构及形式化定义
|
机器学习/深度学习 人工智能 算法
手把手教你快速实现SIFT特征匹配(含源码)
手把手教你快速实现SIFT特征匹配(含源码)
745 0