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'组成,分别 ...
随机推荐
- 【Linux系列】Centos 7安装以及网络配置(一)
目的 本文主要介绍以下两点: 一. 如何在Oracle VM VirtualBox安装centos(已有VirtualBox) 二. 如何在内网里实现虚拟机访问外网.物理主机以及物理主机访问虚拟机 一 ...
- js常用的array方法
1. splice() splice()方法向/从数组中添加/删除项目,然后返回被删除的项目.(注释:该方法会改变原始数组.) arrayObject.splice(index,howmany,i ...
- [LC]141题 Linked List Cycle (环形链表)(链表)
①中文题目 给定一个链表,判断链表中是否有环. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始). 如果 pos 是 -1,则在该链表中没有环. 示例 ...
- Docker解决下载镜像速度慢
Docker安装好以后要用Docker pull命令下载镜像,但是会出现下载很慢的现象.Docker默认是国外的源,配置国内镜像仓库. 1.cd /etc/docker/路径下 2.编辑daemon. ...
- RAID5创建流程(3块做RAID,两块备份)
https://www.cnblogs.com/meng-yu37/p/11739680.html(raid10链接) RAID5和RAID10 配置差不多,这里只指出不同的地方, 2. 使用mdad ...
- python:模块1——标准库简介
一.文档 windows系统:IDLE中打开帮助文档 Tutorial:简单入门 Library Reference:python内置函数和标准库(看不完的,当做字典来查)(此外还有pypi(拍派社区 ...
- PHP字符逃逸导致的对象注入
1.漏洞产生原因: 序列化的字符串在经过过滤函数不正确的处理而导致对象注入,目前看到都是因为过滤函数放在了serialize函数之后,要是放在序列化之前应该就不会产生这个问题 ?php functio ...
- 小白学 Python 爬虫(12):urllib 基础使用(二)
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- JPA配置实体时 insertable = false, updatable = false
当使用JPA配置实体时,如果有两个属性(一个是一般属性,一个是多对一的属性)映射到数据库的同一列,就会报错. 这时,在多对一的@JoinColumn注解中添加insertable = false, u ...
- GItBook命令使用(持续更新)
GitBook基本命令 gitbook init //初始化目录文件 gitbook help //列出gitbook所有的命令 gitbook --help //输出gitbook-cli的帮助信息 ...