2017 CCPC秦皇岛 L题 One Dimensions Dave
BaoBao is trapped in a one-dimensional maze consisting of grids arranged in a row! The grids are numbered from 1 to from left to right, and the -th grid is marked with a character , where is either 'L' or 'R'.
Starting from the -th grid, BaoBao will repeatedly take the following steps until he escapes the maze:
- If BaoBao is in the 1st grid or the -th grid, then BaoBao is considered to arrive at the exit and thus can escape successfully.
 - Otherwise, let BaoBao be in the -th grid. If , BaoBao will move to the -th grid; If , Baobao will move to the -th grid.
 
Before taking the above steps, BaoBao can change the characters in some grids to help himself escape. Concretely speaking, for the -th grid, BaoBao can change from 'L' to 'R', or from 'R' to 'L'.
But changing characters in grids is a tiring job. Your task is to help BaoBao calculate the minimum number of grids he has to change to escape the maze.
Input
There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:
The first line contains two integers and (, ), indicating the number of grids in the maze, and the index of the starting grid.
The second line contains a string () consisting of characters 'L' and 'R'. The -th character of indicates the character in the -th grid.
It is guaranteed that the sum of over all test cases will not exceed .
<h4< dd="">Output
For each test case output one line containing one integer, indicating the minimum number of grids BaoBao has to change to escape the maze.
<h4< dd="">Sample Input
3
3 2
LRL
10 4
RRRRRRRLLR
7 4
RLLRLLR
<h4< dd="">Sample Output
0
2
1
<h4< dd="">Hint
For the first sample test case, BaoBao doesn't have to change any character and can escape from the 3rd grid. So the answer is 0.
For the second sample test case, BaoBao can change to 'R' and to 'R' and escape from the 10th grid. So the answer is 2.
For the third sample test case, BaoBao can change to 'L' and escape from the 1st grid. So the answer is 1.
题解:签到题;分别往两边走即可;去最小值
参考代码:
#include<bits/stdc++.h>
using namespace std;
int t,n,m;
int L(string s)
{
int sum=;
for(int i=m-;i>;i--) if(s[i]=='R') sum++;
return sum;
}int R(string s)
{
int sum=;
for(int i=m-;i<n-;i++) if(s[i]=='L') sum++;
return sum;
}
int main()
{
string s;
cin>>t;
while(t--&&cin>>n>>m>>s) printf("%d\n",R(s)>L(s)?L(s):R(s));
return ;
}
2017 CCPC秦皇岛 L题 One Dimensions Dave的更多相关文章
- 2017 CCPC秦皇岛 A题 A Ballon Robot
		
The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be teams parti ...
 - 2017 CCPC秦皇岛 M题 Safest Buildings
		
PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parach ...
 - 2017 CCPC秦皇岛 E题 String of CCPC
		
BaoBao has just found a string of length consisting of 'C' and 'P' in his pocket. As a big fan of ...
 - 2017 CCPC秦皇岛 H题 Prime set
		
Given an array of integers , we say a set is a prime set of the given array, if and is prime. Ba ...
 - 2017 CCPC秦皇岛 G题 Numbers
		
DreamGrid has a nonnegative integer . He would like to divide into nonnegative integers and minimi ...
 - 2017 ccpc哈尔滨 A题 Palindrome
		
2017 ccpc哈尔滨 A题 Palindrome 题意: 给一个串\(T\),计算存在多少子串S满足\(S[i]=S[2n−i]=S[2n+i−2](1≤i≤n)\) 思路: 很明显这里的回文串长 ...
 - HDU 6268  Master of Subgraph (2017 CCPC 杭州 E题,树分治 + 树上背包)
		
题目链接 2017 CCPC Hangzhou Problem E 题意 给定一棵树,每个点有一个权值,现在我们可以选一些连通的点,并且把这点选出来的点的权值相加,得到一个和. 求$[1, m] ...
 - HDU 6271 Master of Connected Component(2017 CCPC 杭州 H题,树分块 + 并查集的撤销)
		
题目链接 2017 CCPC Hangzhou Problem H 思路:对树进行分块.把第一棵树分成$\sqrt{n}$块,第二棵树也分成$\sqrt{n}$块. 分块的时候满足每个块是一个 ...
 - 2017CCPC秦皇岛 L题One-Dimensional Maze&&ZOJ3992【模拟】
		
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3992 题意: 走迷宫,一个一维字符串迷宫,由'L'.'R'组成,分别 ...
 
随机推荐
- 网络编程--UDP通讯
			
UTP传输 public class Send1 { public static void main(String[] args) throws Exception { Scanner sc=new ...
 - python3 控制安卓手机的飞行模式遇到的问题汇总
			
一.首先调通电脑对手机能落实 adb shell命令 验证通过标准:控制wifi开关的命令,能让wifi功能开启和关闭 (adb shell svc wifi enable 和 adb she ...
 - mysql出现ERROR 1819 (HY000)的解决方法
			
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements, 出现这个问题怎么办? 为了加强安 ...
 - 万恶之源-python的进化
			
列表 列表的增删改查 3. 列列表的嵌套 元组和元组嵌套 5. range ⼀一. 列表 1.1 列表的介绍 列表是python的基础数据类型之⼀一 ,其他编程语⾔言也有类似的数据类型. 比如JS中的 ...
 - [UWP]用Win2D和CompositionAPI实现文字的发光效果,并制作动画
			
1. 成果 献祭了周末的晚上,成功召唤出了上面的番茄钟.正当我在感慨"不愧是Shadow大人,这难道就是传说中的五彩斑斓的黑?" "那才不是什么阴影效果,那是发光效果.& ...
 - 微服务中的Kafka与Micronaut
			
今天,我们将通过Apache Kafka主题构建一些彼此异步通信的微服务.我们使用Micronaut框架,它为与Kafka集成提供专门的库.让我们简要介绍一下示例系统的体系结构.我们有四个微型服务:订 ...
 - 【NHOI2018】跳伞登山赛
			
[题目描述] 某山区有高高低低的 n 个山峰,根据海拔高度的不同,这些山峰由低到高进行了 1 到 n 编号.有 m 条只能单向通行的羊肠小道连接这些山峰.现在,这里要举行一场跳伞登山赛,选手们伞降到某 ...
 - Linux进阶文档丨阿里架构师十年Linux心得,全在这份文档里面
			
Linux是什么 Linux就是个操作系统: 它和Windows XP.Windows 7.Windows 10什么的一样就是一个操作系统而已! Linux能干什么: 它能当服务器,服务器上安装者各种 ...
 - C语言Ⅰ博客作业04
			
问题 回答 这个作业属于哪个课程 c语言程序设计ll 这个作业要求在哪里 https://blog.csdn.net/qq_42264638/article/details/102381471 我在这 ...
 - (python)查看糗事百科文字 点赞 作者 等级 评论
			
import requestsimport reheaders = { 'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; ...