Problem I

Marcus, help!

Input: standard input

Output: standard output

Time Limit: 2 Seconds

"First, the breath of God.

Only the penitent man will pass.

Second, the Word of God,

Only in the footsteps of God will he proceed.

Third, the Path of God,

Only in the leap from the lion's head will he prove his worth."

(taken from the movie "Indiana Jones and the Last Crusade", 1989)

To get to the grail, Indiana Jones needs to pass three challenges. He successfully masters the first one and steps up to the second. A cobblestone path lies before him, each cobble is engraved with a letter. This is the second
challenge, the Word of God, the Name of God. Only the cobbles having one of the letters "IEHOVA" engraved can be stepped on safely, the ones having a different letter will break apart and leave a hole.

Unfortunately, he stumbles and falls into the dust, and the dust comes into his eyes, making it impossible for him to see. So he calls for Marcus Brody and asks Marcus to tell him in which

direction to go to safely reach the other side of the cobblestone path. Because of the dust in his eyes, Indy only can step "forth" to the stone right in front of him or do a side-step to the stone on the "left" or the "right"
side of him. These ("forth", "left", "right") are also the commands Marcus gives to him.

Input

The first line of the input contains a single number indicating the number of test cases that follow.

Each test case starts with a line containing two numbers m and n (2 <= m, n <= 8), the length m and the width n of the cobblestone path. Then follow m lines, each containing n characters ('A' to 'Z', '@',
'#'), the engravement of the respective cobblestone. Indy's starting position is marked with the '@' character in the last line, the destination with the character '#' in the first line of the cobblestone path.

Each of the letters in "IEHOVA" and the characters '@' and '#' appear exactly once in each test case. There will always be exactly one path from Indy's starting position via the stones with the letters "IEHOVA"
engraved on (in that order) to the destination. There will be no other way to safely reach the destination.

Output

For each test case, output a line with the commands Marcus gives to Indy so that Indy safely reaches the other side. Separate two commands by one space character.

Sample Input

2

6 5

PST#T

BTJAS

TYCVM

YEHOF

XIBKU

N@RJB

5 4

JA#X

JVBN

XOHD

DQEM

T@IY

Sample Output

forth forth right right forth forth forth

right forth forth left forth forth right



题意 : 从  @ 出发 ,沿着 IEHOVA  走到 #  ,输出路径 


#include <iostream>
#include <cstdio>
using namespace std;
const int d[3][2]={{0,-1},{-1,0},{0,1}};
const char s[8]={'@','I','E','H','O','V','A','#'};
const char *t[]={"left","forth","right"};
const int maxn=10; char a[maxn][maxn];
bool visited[maxn][maxn];
int n,m,p,q; void input()
{
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
{
getchar();
for(int j=0;j<m;j++)
{
scanf("%c",&a[i][j]);
if(a[i][j]=='@') p=i,q=j;
}
}
} bool judge(int x,int y)
{
if(x>=0 && x<n && y>=0 && y<m) return true;
return false;
} void dfs(int x,int y,int depth)
{
for(int i=0;i<3;i++)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(judge(xx,yy) && a[xx][yy]==s[depth])
{
printf("%s",t[i]);
if(depth<=6) printf(" ");
dfs(xx,yy,depth+1);
}
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
input();
dfs(p,q,1);
printf("\n");
}
return 0;
}

最新文章

  1. Android笔记:通知
  2. ROS学习笔记(三)——ROS安装
  3. .frm,.myd,myi转换为.sql导入数据库
  4. Delphi操作Excel大全
  5. Git sparse checkout
  6. 菜鸟级asp.net 与ms sql server数据库打交道的简单总结
  7. 二师兄VPN加速器
  8. 关于自动刷新CSS
  9. ATL opengl
  10. php测试题
  11. iOS开发实战-时光记账Demo 网络版
  12. ul中li居中显示的table方法
  13. centos6.5安装rabbitmq3.6.14
  14. IO流的操作规律。
  15. Python制作二维码和条形码扫描器 (pyzbar)
  16. Ambari 使用 Hive View 异常处理
  17. 如何为已有的类没有生成toString的方法增强生成toString方法
  18. C#读取Excel,Access数据库
  19. Java SE 基础知识(String,Array)
  20. MySQL只有.frm文件恢复表结构

热门文章

  1. 进程的互斥运行:CreateMutex函数实现只运行一个程序实例
  2. 怎么在在php配置文件中打开php_fileinfo扩展
  3. JVM内存管理及垃圾回收机制
  4. vue 画二维码
  5. 浏览器通知js授权
  6. vue-cli项目中使用mockjs(基础使用和全局配置使用)
  7. sql分组和连接
  8. 自动清除日期目录shell脚本
  9. phtyon,通过while循环简单的用户名和密码登录
  10. Springboot+dubbo+zookeeper整合