HBC14376One-Dimensional Maze题解

2拍不死你 算法基础篇 37 0
想要检验自己的编程水平?来试试全网最全C++题库,让您在挑战中不断进步。
BaoBao is trapped in a one-dimensional maze consisting of ngrids arranged in a row!The grids are numbered from 1 to nfrom left to right, and thei-thgrid is marked with a character si, where si is either 'L' or 'R'. Starting from the m-th grid, BaoBao will repeatedly take the following steps until he escapes the maze: 1.If BaoBao is in the1st grid or the n-th grid, then BaoBao is considered to arrive at the exit and thus can escape successfully. 2.Otherwise, let BaoBao be in the t-th grid. Ifst= 'L',BaoBao will move to the -th grid;Ifst= 'R',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 i-th grid, BaoBao can change si 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.

BaoBao is trapped in a one-dimensional maze consisting of n  grids arranged in a row! The grids are numbered from 1 to n from left to right, and the i-th grid is marked with a character si, where si is either 'L' or 'R'. Starting from the m-th grid, BaoBao will repeatedly take the following steps until he escapes the maze:     1.If BaoBao is in the 1st grid or the n-th grid, then BaoBao is considered to arrive at the exit and thus can escape successfully.     2.Otherwise, let BaoBao be in the t -th grid. If st = 'L', BaoBao will move to the (t - 1)-th grid; If st = 'R', BaoBao will move to the (t + 1)-th grid;  Before taking the above steps, BaoBao can change the characters in some grids to help himself escape. Concretely speaking, for the i-th grid, BaoBao can change si 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.

HBC14376One-Dimensional Maze题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
想要在职场中立于不败之地?那就来试试全网最全C++题库,让您在练习中快速提升技能。

标签: HBC14376One-Dimensional Maze题解