Codeforces-学校排队-程序员宅基地

技术标签: 算法  c++  codeforces 每日一题  数据结构  

B. Queue at the School

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.

Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.

You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.

Input

The first line contains two integers n and t (1 ≤ n, t ≤ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.

The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".

Output

Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".

 

译文

学校排队

时间限制:2 秒

内存限制:256 MB

输入:标准输入

输出:标准输出

课间休息时,男女学生在食堂排起了 n 人的长队。起初,他们按照进入食堂的顺序站好。然而,过了一会儿,男生开始觉得站在女生前面很尴尬,于是他们开始让女生每秒钟向前移动一次。

让我们更精确地描述一下这个过程。假设队列中的位置按 1 到 n 的整数顺序编号,1 号位置上的人先得到服务。那么,如果在第 x 秒时,第 i 个位置上站着一个男孩,第 (i + 1) 个位置上站着一个女孩,那么在第 x + 1 秒时,第 i 个位置上将站着一个女孩,第 (i + 1) 个位置上将站着一个男孩。

你已经得到了学生们在初始时刻的初始位置。确定 t 秒后队列的样子。

输入

第一行包含两个整数 n 和 t(1 ≤ n,t ≤ 50),分别表示队列中的人数和队列转变为所需排列的时间。

下一行包含字符串 s,它代表学生的初始排列。如果队列中的第 i 个位置是男孩,则字符串 s 的对应第 i 个字符等于“B”,否则第 i 个字符等于“G”。

输出

打印字符串 a,表示 t 秒后队列的样子。如果第 i 个位置在 t 秒后是一个男孩,则第 i 个字符必须为 "B",否则为 "G"。

 

样例


输入

5 1

BGGBG

输出

GBGGB


输入

5 2

BGGBG

输出

GGBGB


输入

4 1

GGGB

输出

GGGB


 

题解

#include <bits/stdc++.h>
using namespace std;
int n, t;
string s;
int main()
{
    cin >> n >> t >> s;
    // 需要同时将当前这一秒的所有BG全部改为GB
    while (t--)
    {
        for (int i = 0; i < s.size();)
        {
            if (s[i] == 'B' && s[i + 1] == 'G')
                swap(s[i], s[i + 1]), i += 2;
            else
                i += 1;
        }
    }
    cout << s;
    return 0;
}

 

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/NUJIEW/article/details/135686824

智能推荐

Java通过Socket实现UDP编程及Socket总结_java xsocket jar包,实现udp服务端-程序员宅基地

文章浏览阅读8.5k次,点赞2次,收藏28次。UDPServer.javaimport java.io.IOException;import java.net.DatagramPacket;import java.net.DatagramSocket;import java.net.InetAddress;/* * 服务器端,实现基于UDP的用户登陆 */public class UDPServer { public s_java xsocket jar包,实现udp服务端

pmp项目管理_pmp项目管理实施-程序员宅基地

文章浏览阅读692次,点赞2次,收藏3次。规划采购管理是记录项目采购决策、明确采购方法,及识别潜在卖方的过程。本过程的主要作用 是,确定是否从项目外部获取货物和服务,如果是,则还要确定将在什么时间、以什么方式获取什 么货物和服务。货物和服务可从执行组织的其他部门采购,或者从外部渠道采购。本过程仅开展一 次或仅在项目的预定义点开展。图 12-2 描述本过程的输入、工具与技术和输出。图 12-3 是本过程的 数据流向图。..._pmp项目管理实施

linux bash脚本_如何在Linux终端中显示日期和时间(并在Bash脚本中使用它)-程序员宅基地

文章浏览阅读5.7k次,点赞4次,收藏15次。linux bash脚本Fatmawati Achmad Zaenuri/Shutterstock.comFatmawati Achmad Zaenuri / Shutterstock.com The date command is found in the Bash shell, which is the default shell in most Linux distributions and..._linux terminal显示时间

npm安装报错的解决办法-程序员宅基地

文章浏览阅读3.6k次。npm报错处理_npm安装报错

Unity中按钮(Button)控件Onclick事件函数参数错误 —— C#中的闭包(Closure)_unity 按钮onclick参数类型-程序员宅基地

文章浏览阅读2.5k次。问题本文主要针对的问题是在Unity中对Button类进行Onclick事件绑定的时候出现的函数参数错误进行分析解决,具体例子如下: Button[] button = GetComponentsInChildren<Button>(); int buttonCnt = 3; for (int i = 0; i < buttonCnt; i++) { button[i].SetActive(true); Debug.Log("i: " + i);_unity 按钮onclick参数类型

Halcon矩阵(Matrix)算子详解_get_full_matrix-程序员宅基地

文章浏览阅读6.5k次,点赞5次,收藏43次。Halcon矩阵(Matrix)详细说明创建(Creation)create_matrixcopy_matrixrepeat_matrix访问(Access)算法(Arithmetic)分解(Decomposition)特征值(Eigenvalues)特性(Features)文件操作(File)新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注_get_full_matrix

随便推点

TPM概述-程序员宅基地

文章浏览阅读337次。TPM(Trusted Platform Module)安全芯片,是指符合TPM(可信赖平台模块)标准的安全芯片。标准由TCG(可信赖计算组织,Trusted Computing Group)提出,目前最新版本为2.0。符合TPM的芯片首先必须具有产生加解密密钥的功能,此外还必须能够进行高速的资料加密和解密,以及充当保护BIOS和操作系统不被修改的辅助处理器。TPM的可信基础来源于可信根,可信根(..._tpm 总线监听

一天什么时间发抖音浏览量高?5个抖音最佳发布时间段_几点发抖音浏览量最高-程序员宅基地

文章浏览阅读6.7w次。也就更容易获得更高的浏览量。,我们称为午高峰,这个时间段主要是针对一二线城市的上班族,因为玩抖音的一二线城市的人比较多,所以这个时间段他们基本都是下班的时间段,刷抖音的人也很多。,我们成为晚高峰,这个时间段的人基本都忙完工作在休息了,这个时间段可以说是一天中抖音流量最高的时间段,是高峰中的高峰。,这一个时间段的人大都是刚刚睡醒,躺在床上刷一刷抖音,或者在上班的路上没事看看抖音,坐公交的路上刷着抖音。,我们称之为午高峰,这个时间段是人们的午休时间,这个时间段刷抖音的人也很多,吃完饭午休,拿着手机刷刷抖音。_几点发抖音浏览量最高

图数据可视化——R语言ggplot2包和tidybayes包绘制小提琴图进阶_分半小提琴图-程序员宅基地

文章浏览阅读6.1k次,点赞7次,收藏41次。图数据可视化_R语言ggplot2包和tidybayes包绘制小提琴图进阶概述:绘制小提琴图时按数据分布的密度填充不同透明度的颜色(渐变填充)。使用工具:R语言中的ggplot2和tidybayes工具包本文使用的数据及计算方式与之前的博文一致:数据可视化——R语言ggplot2包绘制精美的小提琴图(并箱线图或误差条图组合)。本文采用tidybayes包中stat_eye()绘制小提琴图,通过设置aes(alpha = stat(f)可实现渐变填充。由于stat_eye()会默认采用中位数及分位数作_分半小提琴图

江苏省专转本计算机专业大类《计算机基础理论 1.2(二)小节习题答案》_计算机硬件系统是执行软件程序的物质基础,其中能执行程序指令的是( )-程序员宅基地

文章浏览阅读1.4k次。江苏省专转本计算机_计算机硬件系统是执行软件程序的物质基础,其中能执行程序指令的是( )

教你玩Robocode(3) —— 坦克基础知识_robocode炮和机身的运动分离-程序员宅基地

文章浏览阅读4.4k次。在Robocode中,坦克分为3个部件: 身体(Body)、炮塔(Gun)、雷达(Radar)。 因此,在Robot类(还记得吗,它是任何坦克的父类)中,有对这些部件操作的方法。要查看Robocode提供的API,可以在robocode目录下的javadoc下找到,也可以在Robocode程序的帮助菜单中找到: 对于Body来说,Robot类提供了4个方法:_robocode炮和机身的运动分离

The number of divisors(约数) about Humble Numbers hdu 1492-程序员宅基地

文章浏览阅读77次。Problem DescriptionA number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first...

推荐文章

热门文章

相关标签