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
不要网上的复制粘贴 希望是自己做的
急求C++程序小问题,输入年份和月份,输出该月的天数。
【解题思路】本题的难点主要就是判断是否闰年和大小月份,判断闰年的标准是能被4整除且不能被100整除的年份,或者能被400整除的年份是闰年。至于大小月,则可以通过一个switch……case语句来实现。具体代码如下:【程序代码】#include <iostream> \/\/控制台操作头文件int main() \/\/主函数 {int y...
急求这几个C++问题的答案,英文更佳
3、C\/C++ 里大多数运算符都可以在 C++ 中被重载。只有 . 和 ? :和::和.*不可被重载,此外 sizeof()也不可以被重载。限制是:该组重载函数中任何两个都必须有不同的参量表。具有相同类型参量表、仅在返回值类型上不同的重载函数会引起错误。
c++问题 急求 !!!
1)main ( ){ long i;float bonus,bon1,bon2,bon4,bon6,bon10;bon1=100000*0.1; \/*利润为10万元时的奖金*\/ bon2=bon1+100000*0.075; \/*利润为20万元时的奖金*\/ bon4=bon2+100000*0.05; \/*利润为40万元时的奖金*\/ bon6=bon4+100000*0.03; \/*利润为60万元时的...
急求用C++编一个程序,题目是英文的。题目如下
在main()函数,上面为每个类创建一个对象,输出最大的周长和面积的对象。然后申请+操作正方形对象,再比较周长和面积。注意:如果你可以声明一个全局函数如下,以找出最大的面积或周长的对象,你可以得到一个5分的额外奖励,平方米*发现的最大面积(平方米* S1,平方* S2平方米* S3)...
急求一个C++程序!!!求100以内的自然数能被13整除的最大数的程序。_百度...
int main(){ for(i=99;i>0;i--)if(i%13 == 0)break;printf("100以内的自然数能被13整除的最大数为%d\\n",i);return 0;}
c++问题,x+=x-=x*x,int x=5,x的值为多少,怎么算的呢?急求,明天考试了...
先算 x-=x*x, 也就是 x=x-x*x=5-5*5=-20 再算 x+=-20, 也就是 x=x+(-20)=-40 最终x=-40 你直接写程序验证一下不就完了?
c++火柴棍问题,急求,程序到是其次,递归请帮忙谢谢
那么你每次拿完后剩下的最少要大于9根,否则你就输。20 = t * (1 + 3) t = 5 ;你手中第一堆拿完之后最少火柴根数是 5 根,对方手中最多是 15根 你就把这个所有可能性都列举出来。然后跟据最后想赢分析出来的结果进行判断即可得出结论。
急求,c++的递归函数问题,编写一个程序求S=3+33+333+……+33…33_百度...
include<stdio.h> include<stdlib.h> int re(int n){ if(n==1)return 3;else return re(n-1)+re(n-1)*10+3;} int main(){ printf("%d, %d, %d\\n", re(1), re(2), re(3));} 运行结果:3, 36, 399 想加到n位3,就调用re(n)就可以。
跪求一道c++简单计算题答案
1. 操作符优先级 2. 类型提升 该表达式中的优先级排序:() > (类型转换) > *、\/、% > + 所以其求解顺序为:x+a%3*(int)(x+y)%2\/4 =x+a%3*(int)7.2%2\/4 =x+a%3*7%2\/4 =x+1*7%2\/4 =x+7%2\/4 =x+1\/4 =x+0 =x+0.0 \/\/类型提升,将整型的0提升为表达...
求解C++问题!!急求!!!编写程序统计某文中出现 if while for 单词的...
int main(int argc, char* argv[]){ HANDLE hOpenfile = NULL;char cstr[256];DWORD dwReadSize = 0;BOOL bRet = false;long if_num = 0;long while_num = 0;long for_num = 0;memset(cstr,0x00,sizeof(cstr));hOpenfile = CreateFile("1.txt",GENERIC_WRITE|GENERIC_READ,0,NULL...