CF2204A.Passing the Ball
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
During a physical education class, n students are lined up, numbered from 1 to n from left to right.
For each student, it is known that if they receive the ball, they will pass it either to the neighbor on their left or to the neighbor on their right. This is specified by a string s of n characters. Each character of the string is either L or R, where si is L if the i-th student passes the ball to student (i−1), or si is R if the i-th student passes the ball to student (i+1). The first student always passes the ball to the second, and the last one to the second last (in other words, the string s starts with the character R and ends with the character L).
Consider the following process:
- first, the first student receives the ball;
- then, exactly n times, the following occurs: the student who currently has the ball passes it to their neighbor (according to the rules described above).
Your task is to determine how many students will receive the ball at least once during this process.
在体育课上,n 名学生排成一列,从左到右依次编号为 1 到 n。
对于每名学生,已知:若其接到球,则会将球传给左侧相邻的同学或右侧相邻的同学。该行为由一个长度为 n 的字符串 s 描述。字符串中每个字符为 L 或 R:若第 i 名学生将球传给第 (i−1) 名学生,则 si 为 L;若第 i 名学生将球传给第 (i+1) 名学生,则 si 为 R。特别地,第一名学生总是将球传给第二名学生,最后一名学生总是将球传给倒数第二名学生(即字符串 s 以字符 R 开头,以字符 L 结尾)。
考虑如下过程:
- 首先,第一名学生接到球;
- 然后,恰好进行 n 次传球:当前持球的学生根据上述规则将球传给其相邻同学。
你的任务是确定在此过程中,至少接到一次球的学生人数。
输入格式
The first line contains a single integer t (1≤t≤10000) — the number of test cases.
Each test case consists of two lines:
- the first line contains a single integer n (2≤n≤50) — the number of students;
- the second line contains s — a sequence of n characters L and R. The first character of the sequence is R, and the last is L.
第一行包含一个整数 t(1≤t≤10000)—— 测试用例的数量。
每个测试用例由两行组成:
- 第一行包含一个整数 n(2≤n≤50)—— 学生的数量;
- 第二行包含字符串 s —— 一个由 n 个字符 L 和 R 组成的序列。该序列的第一个字符为 R,最后一个字符为 L。
输出格式
For each test case, print one integer — the number of students who will receive the ball at least once during the described process.
对于每个测试用例,输出一个整数——在上述过程中至少接到一次球的学生人数。
输入输出样例
输入#1
3 4 RLRL 6 RRRRRL 9 RRLRRRRRL
输出#1
2 6 3
说明/提示
In the first example, student 1 receives the ball and passes it to student 2, who returns it back to student 1, who passes it back to student 2, and so on. Only students 1 and 2 received the ball.
In the second example, student 1 passes the ball to student 2, who passes it to student 3, who passes it to student 4, who passes it to student 5, who passes it to student 6, who returns it to student 5. Each student received the ball at least once.
在第一个例子中,学生 1 接到球后将其传给学生 2,学生 2 又将球传回学生 1,学生 1 再将球传回学生 2,如此反复。只有学生 1 和学生 2 接到过球。
在第二个例子中,学生 1 将球传给学生 2,学生 2 传给学生 3,学生 3 传给学生 4,学生 4 传给学生 5,学生 5 传给学生 6,学生 6 再将球传回学生 5。每位学生至少接到过一次球。
输入解题思路,AI测评打分。不知道怎么写?