急求一道C++题目
Thereisarobottrappedinthemaze.Nowyouhavetosendoutsomeinstructions,tellingithowtoreach...
There is a robot trapped in the maze. Now you have to send out some instructions, telling it how to reach its destination.
The maze is an M * N grid. Some of the cells are empty, while others are occupied by the wall. Of course the robot can't move into the wall, and the robot can't move outside the grid too. The robot can only accept three commands: TURN LEFT, TURN RIGHT and GO. The robot may face to North, South, East or West during the movement. When it receive a TURN LEFT command, it will rotate 90 degree to the left. That is, if it faces to east before the command, it will face to north after the TURN LEFT command. The TURN RIGHT command is almost the same, except that the direction is opposite. When receive the GO command, the robot will move 1 unit towards its orientation, unless there is a nonempty cell in front of it.
Please note the robot is always face to north at the beginning, i.e., face to the upper border in the maze map. (The maze map will be described below.)
You want to use minimum number of instructions, so you should write a program for help.
Input Format: (b3.in)
The first line of the input is the number of test cases.
The first line of each test case contains two integers M and N, indicating the size of the maze. There are M lines followed, each line contains exactly N characters, describing an M * N maze. The '#' indicating the wall, the '.' indicating the empty cell, the 'S' and 'T' indicating the start point and the destination of the robot respectively. There are no other characters in the maze map.
The orientation of the maze map is just the same as the common sense. That is, the upper-left corner of the maze map indicating the north-west direction, and the lower-right corner indicating the south-east.
You can assume 1 ≤ M ≤ 100 and 1 ≤ N ≤ 100. There is only one 'S' and one 'T' in the maze.
Output Format: (b3.out)
Output one line for each test case, indicating the minimum number of instructions needed. Or output -1 if it's impossible to reach the robot's destination.
Sample Input:
2
5 5
#####
#...#
#.#.#
#S#T#
#####
4 5
#.#.#
#.#.#
#S#T#
#####
Sample Output:
8
-1
不要网上的复制粘贴 希望是自己做的 展开
The maze is an M * N grid. Some of the cells are empty, while others are occupied by the wall. Of course the robot can't move into the wall, and the robot can't move outside the grid too. The robot can only accept three commands: TURN LEFT, TURN RIGHT and GO. The robot may face to North, South, East or West during the movement. When it receive a TURN LEFT command, it will rotate 90 degree to the left. That is, if it faces to east before the command, it will face to north after the TURN LEFT command. The TURN RIGHT command is almost the same, except that the direction is opposite. When receive the GO command, the robot will move 1 unit towards its orientation, unless there is a nonempty cell in front of it.
Please note the robot is always face to north at the beginning, i.e., face to the upper border in the maze map. (The maze map will be described below.)
You want to use minimum number of instructions, so you should write a program for help.
Input Format: (b3.in)
The first line of the input is the number of test cases.
The first line of each test case contains two integers M and N, indicating the size of the maze. There are M lines followed, each line contains exactly N characters, describing an M * N maze. The '#' indicating the wall, the '.' indicating the empty cell, the 'S' and 'T' indicating the start point and the destination of the robot respectively. There are no other characters in the maze map.
The orientation of the maze map is just the same as the common sense. That is, the upper-left corner of the maze map indicating the north-west direction, and the lower-right corner indicating the south-east.
You can assume 1 ≤ M ≤ 100 and 1 ≤ N ≤ 100. There is only one 'S' and one 'T' in the maze.
Output Format: (b3.out)
Output one line for each test case, indicating the minimum number of instructions needed. Or output -1 if it's impossible to reach the robot's destination.
Sample Input:
2
5 5
#####
#...#
#.#.#
#S#T#
#####
4 5
#.#.#
#.#.#
#S#T#
#####
Sample Output:
8
-1
不要网上的复制粘贴 希望是自己做的 展开
展开全部
目前被困在迷宫机器人。现在你必须要发出一些指令,告诉它如何到达目的地。
迷宫是一个m *不发车。对一些牢房是空的,有些则占领了墙上。当然,机器人不能移动到墙上,和机器人还不能在网格移动外也。该机器人只能接受三个命令:左转,右转。这个机器人可能面临北,南,东或西运动期间。当它收到左转命令,它会旋转90度到左边。也就是说,如果向东面临命令之前,将面对后左转命令北部。在右转命令几乎相同,只是方向是相反的。当收到GO命令,机器人将走向它的方向1个单位,除非有在它前面空细胞。
请注意机器人总是面对一开始,即在面对迷宫地图上的边界以北。 (迷宫图将说明如下。)
您想使用最少的指令,所以你应该写一个程序的帮助。
输入格式:(b3.in)
在输入的第一行是测试的个案。
每个测试案例的第一行包含两个整数M和N,表明迷宫的大小。有M线后,每行正好包含N个字符,描述的M *不迷宫。在'#',显示墙,'。显示空单元格,了'S'和'T'表示的开始点和目的地分别机器人。还有迷宫地图在任何其它字符。
在迷宫地图定位只是作为常识一样。也就是说,左上角的迷宫角落地图,标明西北方向,右下角显示东南部。
你可以假设1≤M≤100和1≤ñ≤100。只有一个'S'和一个'T的迷宫'。
输出格式:(b3.out)
输出一行为每个测试案例,表明所需要的最低数量的指示。或输出-1,如果这是不可能实现机器人的目的地。
示例输入:
此题英文翻译,供编程高手参考
迷宫是一个m *不发车。对一些牢房是空的,有些则占领了墙上。当然,机器人不能移动到墙上,和机器人还不能在网格移动外也。该机器人只能接受三个命令:左转,右转。这个机器人可能面临北,南,东或西运动期间。当它收到左转命令,它会旋转90度到左边。也就是说,如果向东面临命令之前,将面对后左转命令北部。在右转命令几乎相同,只是方向是相反的。当收到GO命令,机器人将走向它的方向1个单位,除非有在它前面空细胞。
请注意机器人总是面对一开始,即在面对迷宫地图上的边界以北。 (迷宫图将说明如下。)
您想使用最少的指令,所以你应该写一个程序的帮助。
输入格式:(b3.in)
在输入的第一行是测试的个案。
每个测试案例的第一行包含两个整数M和N,表明迷宫的大小。有M线后,每行正好包含N个字符,描述的M *不迷宫。在'#',显示墙,'。显示空单元格,了'S'和'T'表示的开始点和目的地分别机器人。还有迷宫地图在任何其它字符。
在迷宫地图定位只是作为常识一样。也就是说,左上角的迷宫角落地图,标明西北方向,右下角显示东南部。
你可以假设1≤M≤100和1≤ñ≤100。只有一个'S'和一个'T的迷宫'。
输出格式:(b3.out)
输出一行为每个测试案例,表明所需要的最低数量的指示。或输出-1,如果这是不可能实现机器人的目的地。
示例输入:
此题英文翻译,供编程高手参考
展开全部
...我知道怎么编了。。但是要编好久~估计要两个小时~懒得编了~说说想法吧,定义迷宫和机器人两个类,然后对机器人可以走的路用穷举走遍,计算步数,输出最小步数就好。顺便说一句,这个应该是某某acm online judge的题,如果连题都看不懂,也很难期待他能编出来啦~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
能说中文吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
额...没看懂题目
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我六级还差七分。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询