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. 使用CXF发布webservice服务及注意要点

    一.概念 1.什么是webservice Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML标准来描述.发布.发现.协调和配置这些应用程序,用 ...

  2. beyong Compare4解决30天的评估期结束

    刚开始是删掉注册表的CacheId(无效) 1.在搜索栏中输入 regedit ,打开注册表2.删除项目CacheId :HKEY_CURRENT_USER\Software\Scooter Soft ...

  3. java编程思想第四版第九章习题

    第三题 package net.mindview.interfaces; abstract class Base{ public Base(){ print(); } abstract void pr ...

  4. pat 1077 Kuchiguse(20 分) (字典树)

    1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal ...

  5. android逆向总结

    首先项目里的java文件,以及项目引用到的第三方jar或aar包里面的class,统统都编译成classes.dex放在apk包的根目录,项目的资源目录和AndroidManifest.xml被处理生 ...

  6. [springboot 开发单体web shop] 8. 商品详情&评价展示

    上文回顾 上节 我们实现了根据搜索关键词查询商品列表和根据商品分类查询,并且使用到了mybatis-pagehelper插件,讲解了如何使用插件来帮助我们快速实现分页数据查询.本文我们将继续开发商品详 ...

  7. 在input输入值改变reducer里的值

    输入值改变reducer里的值 通过store.dispatch传入reducer中,函数的第二个参数可以接收到 在reducer中 在todolist文件中 然后在把this.state中的值改变

  8. PostGIS安装教程

    安装环境: win10专业版 postgresql-10.6-1-windows-x64 ---因为使用的是ArcGIS10.4版本,pg10.6对于ArcGIS10.4版本过高,建议选择安装pg9. ...

  9. GitHub上优秀的开源项目(转载)

    转载出处:https://github.com/Trinea/android-open-project 第一部分 个性化控件(View) 主要介绍那些不错个性化的 View,包括 ListView.A ...

  10. 使用 buildx 构建多平台 Docker 镜像

    原文链接:使用 buildx 构建多平台 Docker 镜像 在工作和生活中,我们可能经常需要将某个程序跑在不同的 CPU 架构上,比如让某些不可描述的软件运行在树莓派或嵌入式路由器设备上.特别是 D ...