编程介的小学生 2020-02-14 21:49 采纳率: 20.5%
浏览 81

Swipe Bo 的实现的问题

Problem Description
“Swipe Bo” is a puzzle game that requires foresight and skill.
The main character of this game is a square blue tofu called Bo. We can swipe up / down / left / right to move Bo up / down / left / right. Bo always moves in a straight line and nothing can stop it except a wall. You need to help Bo find the way out.
The picture A shows that we needs three steps to swipe Bo to the exit (swipe up, swipe left, swipe down). In a similar way, we need only two steps to make Bo disappear from the world (swipe left, swipe up)!

Look at the picture B. The exit is locked, so we have to swipe Bo to get all the keys to unlock the exit. When Bo get all the keys, the exit will unlock automatically .The exit is considered inexistent if locked. And you may notice that there are some turning signs, Bo will make a turn as soon as it meets a

turning signs. For example, if we swipe Bo up, it will go along the purple line.
Now, your task is to write a program to calculate the minimum number of moves needed for us to swipe Bo to the exit.

Input
The input contains multiple cases, no more than 40.
The first line of each test case contains two integers N and M (1≤N, M≤200), which denote the sizes of the map. The next N lines give the map’s layout, with each line containing M characters. A character is one of the following: '#': represents the wall; 'S' represents the start point of the Bo; 'E' represents the exit; '.' represents an empty block; ‘K’ represents the key, and there are no more than 7 keys in the map; 'L','U','D','R' represents the turning sign with the direction of left, up, down, right.

Output
For each test case of the input you have to calculate the minimal amount of moves which are necessary to make Bo move from the starting point to the exit. If Bo cannot reach the exit, output -1. The answer must be written on a single line.

Sample Input
5 6
######
#....#
.E...#
..S.##
.#####
5 6
######
#....#
.....#
SEK.##
.#####
5 6
######
#....#
....K#
SEK.##
.#####
5 6
######
#....#
D...E#
S...L#
.#####

Sample Output
3
2
7
-1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥30 用arduino开发esp32控制ps2手柄一直报错
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿