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的更多相关文章

  1. 2017 CCPC秦皇岛 A题 A Ballon Robot

    The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be  teams parti ...

  2. 2017 CCPC秦皇岛 M题 Safest Buildings

    PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parach ...

  3. 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 ...

  4. 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 ...

  5. 2017 CCPC秦皇岛 G题 Numbers

    DreamGrid has a nonnegative integer . He would like to divide  into nonnegative integers  and minimi ...

  6. 2017 ccpc哈尔滨 A题 Palindrome

    2017 ccpc哈尔滨 A题 Palindrome 题意: 给一个串\(T\),计算存在多少子串S满足\(S[i]=S[2n−i]=S[2n+i−2](1≤i≤n)\) 思路: 很明显这里的回文串长 ...

  7. HDU 6268 Master of Subgraph (2017 CCPC 杭州 E题,树分治 + 树上背包)

    题目链接  2017 CCPC Hangzhou  Problem E 题意  给定一棵树,每个点有一个权值,现在我们可以选一些连通的点,并且把这点选出来的点的权值相加,得到一个和. 求$[1, m] ...

  8. HDU 6271 Master of Connected Component(2017 CCPC 杭州 H题,树分块 + 并查集的撤销)

    题目链接  2017 CCPC Hangzhou Problem H 思路:对树进行分块.把第一棵树分成$\sqrt{n}$块,第二棵树也分成$\sqrt{n}$块.    分块的时候满足每个块是一个 ...

  9. 2017CCPC秦皇岛 L题One-Dimensional Maze&&ZOJ3992【模拟】

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3992 题意: 走迷宫,一个一维字符串迷宫,由'L'.'R'组成,分别 ...

随机推荐

  1. 花了几个小时总结了一些容易出错的 Java 知识点!

    本文已经收录自 JavaGuide (61k+Star![Java学习+面试指南] 一份涵盖大部分Java程序员所需要掌握的核心知识.欢迎 Star!欢迎骚扰!) 原文地址:https://javag ...

  2. 二、netcore跨平台之 Linux部署nginx代理webapi

    上一章,我们讲了在linux上安装netcore环境,以及让netcore在linux上运行. 这一章我们开始讲在linux上配置nginx,以及让nginx反向代理我们的webapi. 什么ngin ...

  3. Ubuntu 16.04.4 LTS设置root用户登陆图形界面

    普通用户登陆真是太憋屈,这也不能那也不能,root用户登录就可以肆无忌惮了 本方法采用nano编辑器,ubantu版本Ubuntu 16.04.4 LTS,其他版本应该也一样,下面进入正题 1.终端登 ...

  4. 🔥「课代表」帮你总结了全网最全的Redis知识点

    你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图.个人联系方式和人才交流群,欢迎Star和指教 ...

  5. requests保存图片

    1.创建07_save_jpg.py文件 import requests #发送请求respone = requests.get("https://www.baidu.com/img/bd_ ...

  6. 力扣(LeetCode)加一 个人题解

    给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: 输入 ...

  7. python:类4——魔法方法(定制序列、迭代)、生成器、推导式

    一.定制序列(容器类型) http://bbs.fishc.com/forum.php?mod=viewthread&tid=48793&extra=page%3D1%26filter ...

  8. Mac上安装并配置JDK

    1,下载 点击 官网 ,进入下载界面, 同意协议内容 找到对应的Mac版本, 2,安装 安装下载下来的文件,期间会要求输入一次电脑密码,然后自动安装完. 如果显示文件已经损坏,打开 终端 输入 sud ...

  9. HashSet源码学习,基于HashMap实现

    HashSet源码学习 一).Set集合的主要使用类 1). HashSet 基于对HashMap的封装 2). LinkedHashSet 基于对LinkedHashSet的封装 3). TreeS ...

  10. Error: Cannot find module 'less'

    这是webpack.config 代码中引入 报错信息(在main.js中引入也是这个报错 解决办法: 安装less: npm install less --save-dev 转自: https:// ...