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;
}


相关文章
|
人工智能 vr&ar
AIGC领域又有大动作了!AI视频“黑马”Morph Studio 来袭,1080P高清画质视频免费生成!
AIGC领域又有大动作了!AI视频“黑马”Morph Studio 来袭,1080P高清画质视频免费生成!
882 2
|
SQL 存储 druid
Minerva -- Airbnb 的大规模数据指标系统 Part 3
Minerva -- Airbnb 的大规模数据指标系统 Part 3
1174 0
Minerva -- Airbnb 的大规模数据指标系统 Part 3
|
11月前
|
监控 NoSQL 中间件
阿里云服务器通用算力型u2a实例性能、适用场景,最新收费标准与活动价格参考
本文聚焦阿里云2026年通用算力型u2a实例,该实例基于AMD CPU平台打造,支持跨平台热迁移,适配多代际CPU处理器。其搭载AMD EPYC处理器,在MySQL、Redis等数据库应用中性能提升超50%,适配中小型网站、应用服务器及中间件服务等多场景。文章详细解析了u2a实例的规格配置、按量付费与包年包月价格体系,以及2026年新用户2.5折优惠活动,并提供业务场景匹配建议与成本优化策略,助力中小企业及个人用户低成本高效上云。
693 1
|
7月前
|
供应链 安全 网络协议
从Silver Fox新变种看2026年网络钓鱼的攻防进化
2026年初,德企Hexastrike披露“银狐”团伙利用AtlasCross RAT木马,通过伪造Zoom、Signal等知名软件域名实施精准钓鱼。攻击融合拼错域名、盗用代码签名证书、无文件内存注入及针对性反杀软技术,严重威胁亚洲商务与财务人员安全。
622 3
|
9月前
|
安全 机器人 Linux
零基础零技术|OpenClaw阿里云+本地多系统部署+千问/Coding Plan API配置+钉钉接入全指南
OpenClaw(原Clawdbot,昵称“龙虾”)是一款开源AI自动化代理框架,核心功能是通过自然语言指令拆解,调用各类技能完成文件管理、办公协同、数据抓取、代码生成等重复性任务,无需手动编写脚本,大幅提升个人与轻量团队的工作效率。其核心依赖大模型提供推理能力,自身不具备独立的自然语言理解与任务规划能力,因此部署流程、API配置以及办公工具接入,成为零基础用户落地OpenClaw的核心痛点。
1273 0
|
XML 前端开发 Android开发
一篇文章带你走近Android自定义view
这是一篇关于Android自定义View的全面教程,涵盖从基础到进阶的知识点。文章首先讲解了自定义View的必要性及简单实现(如通过三个构造函数解决焦点问题),接着深入探讨Canvas绘图、自定义属性设置、动画实现等内容。还提供了具体案例,如跑马灯、折线图、太极图等。此外,文章详细解析了View绘制流程(measure、layout、draw)和事件分发机制。最后延伸至SurfaceView、GLSurfaceView、SVG动画等高级主题,并附带GitHub案例供实践。适合希望深入理解Android自定义View的开发者学习参考。
1141 84
|
前端开发 JavaScript Java
SpringCloudGateway网关服务实现文件上传功能
SpringCloudGateway网关服务实现文件上传功能
999 7
|
人工智能 前端开发 API
OpenAI 12天发布会内容全纪录!一文快速回顾获知亮点信息,原文附发布会中文字幕视频
OpenAI 于12月5日宣布将举行为期12天的系列发布活动,期间每天发布一个产品或样品,包括备受期待的AI视频生成工具Sora和新的推理模型。本文将介绍这12天的发布会每日的发布内容和相关亮点信息。
1598 82
|
存储 Go 开发者
解释 Golang 中的 switch 语句
【8月更文挑战第31天】
637 1
|
机器学习/深度学习 人工智能 自然语言处理
AI 古籍修复技术
AI 古籍修复技术
1358 0