CF1927A.Make it White
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a horizontal strip of n cells. Each cell is either white or black.
You can choose a continuous segment of cells once and paint them all white. After this action, all the black cells in this segment will become white, and the white ones will remain white.
What is the minimum length of the segment that needs to be painted white in order for all n cells to become white?
你有一条包含 n 个格子的水平条带。每个格子要么是白色,要么是黑色。
你可以恰好选择一段连续的格子,并将它们全部涂成白色。执行该操作后,这段区间内所有黑色格子都会变为白色,而原本就是白色的格子保持不变。
为了让全部 n 个格子都变为白色,需要涂白的区间的最小长度是多少?
输入格式
The first line of the input contains a single integer t (1≤t≤104) — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains a single integer n (1≤n≤10) — the length of the strip.
The second line of each test case contains a string s, consisting of n characters, each of which is either 'W' or 'B'. The symbol 'W' denotes a white cell, and 'B' — a black one. It is guaranteed that at least one cell of the given strip is black.
输入的第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。接下来是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤10),表示条带的长度。
每个测试用例的第二行包含一个长度为 n 的字符串 s,其中每个字符均为 'W' 或 'B'。字符 'W' 表示白色格子,'B' 表示黑色格子。保证给定条带中至少有一个黑色格子。
输出格式
For each test case, output a single number — the minimum length of a continuous segment of cells that needs to be painted white in order for the entire strip to become white.
对于每个测试用例,输出一个数字——为使整个纸带变为白色,需要涂成白色的连续单元格段的最小长度。
输入输出样例
输入#1
8 6 WBBWBW 1 B 2 WB 3 BBW 4 BWWB 6 BWBWWB 6 WWBBWB 9 WBWBWWWBW
输出#1
4 1 1 2 4 6 4 7
说明/提示
In the first test case of the example for the strip "WBBWBW", the minimum length of the segment to be repainted white is 4. It is necessary to repaint to white the segment from the 2-nd to the 5-th cell (the cells are numbered from 1 from left to right).
在示例的第一个测试用例中,对于条带 "WBBWBW",需要重新涂成白色的最短区段长度为 4。必须将第 2 个到第 5 个单元格(单元格从左到右编号,起始编号为 1)重新涂成白色。
输入解题思路,AI测评打分。不知道怎么写?