当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3137:No Left Turns

题目描述


ALL HEADS: You're a Knight of the Round Table?

ROBIN: I am.

LEFT HEAD: In that case I shall have to kill you.

MIDDLE HEAD: Shall I?

RIGHT HEAD: Oh, I don't think so.

MIDDLE HEAD: Well, what do I think?

LEFT HEAD: I think kill him.

RIGHT HEAD: Well let's be nice to him.

MIDDLE HEAD: Oh shut up.

As the story goes, the Knight scarpers off. Right Head has taken it upon himself to search the grounds for the knight so he, Left, and Middle can go extinguish him (and then have tea and biscuits.)

Consider the following 8 by 12 maze, where shaded squares are walls that can’t be entered.


The shortest path between the Right Head (denoted by the S, for start) and the knight (denoted by the F, for finish) is of length 3, as illustrated above. But! Right Head can’t turn left or make UTurns. He can only move forward and turn right. That means the shortest path that Right Head can find is significantly longer: at 29!


输入解释
The input file will consist of a single integer N (N > 0) specifying the number of mazes in the file. Following this, on a maze by maze basis will be the number of rows, r (3 < r <= 20), a space, then the number of columns, c (3 < c <= 20). After this will follow r lines of c characters, representing a map of the maze:

XXXXXXXXXXXXXX
X XXX
X XFXXXXX X
XXX XX XX X
X S X
XX XXXXXX X X
X X X X
X X X X X
XXX XX X
XXXXXXXXXXXXXX

X’s mark those locations that are walls and can’t be occupied. S marks the start location, and F marks the Knight. Blanks are locations that can be freely traveled.
输出解释
The output is the length of the shortest path between the start and finish locations. Based on the above maze, your program would output the minimum no-left-turns path length of 29.

Hint

Additional Constraints/Information:
  • Right Head is capable of moving from the start position in any of the four primary compass directions. After that, he’s constrained to either step forward or right.

  • The start and end locations will never be the same.

  • The maze is always surrounded by four walls.

  • You can assume that a path between the start and final locations always exists.

输入样例
1
10 14
XXXXXXXXXXXXXX
X          XXX
X XFXXXXX    X
XXX   XX  XX X
X S          X
XX  XXXXXX X X
X        X X X
X X      X X X
XXX XX       X
XXXXXXXXXXXXXX
输出样例
29
来自杭电HDUOJ的附加信息
Recommend chenrui

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3137

最后修改于 2020-10-25T23:00:27+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)