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;
}

uva 10452 Marcus的更多相关文章

  1. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  2. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  3. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  4. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  5. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  6. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

  7. UVA - 1625 Color Length[序列DP 代价计算技巧]

    UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这 ...

  8. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  9. UVA - 11584 Partitioning by Palindromes[序列DP]

    UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...

随机推荐

  1. Zend Studio 离线汉化包下载方法

    进入eclipse官网 语言包位置 http://www.eclipse.org/babel/downloads.php

  2. CAD参数绘制线型标注(网页版)

    主要用到函数说明: _DMxDrawX::DrawDimRotated 绘制一个线型标注.详细说明如下: 参数 说明 DOUBLE dExtLine1PointX 输入第一条界线的起始点X值 DOUB ...

  3. 五、面向切面的spring(1)

    spring的依赖注入看完了,接下来是spring中与DI一并重要的AOP了,开始吧,GO. 在软件开发中,散布于应用中多处的功能被称为横切发关注点,通常来讲,这些横切关注点从概念上市与应用的业务逻辑 ...

  4. ES5和ES6新的操作数组的方法(常用)

    // 普通的for循环// var arr = ['张飞', '赵云', '马超', '刘备']// for (var i = 0; i < arr.length; i++) {// conso ...

  5. PHP解惑(一)

    PHP给人的印象是入门简单的语言.当你的技术能力达到一定阶段时,会发现情况并非如此. PHP采用"极简主义",就是以入门容易为准则设计的,在十几年的持续发展历程中,它早已成为一个开 ...

  6. 树莓派 -- 输入设备驱动 (key)

    输入设备(如按键,键盘,触摸屏等)是典型的字符设备,其一般工作原理是底层在按键或触摸等动作发生时产生一个中断,然后CPU通过SPI,I2C总线读取键值. 在这些工作中之后中断和读键值是与设备相关的,而 ...

  7. Sax解析xml文档

    测试的xml数据: <?xml version="1.0" encoding="utf-8" ?> <note> <to>G ...

  8. rbac组件之菜单操作(三)

    菜单包括菜单列表,菜单列表不仅将菜单列出来,而且将每个菜单下的权限也列出来.菜单的添加.删除.修改. urls.py ... re_path(r'^menus/list/$', MenuView.as ...

  9. Spider-Python爬虫之XPath 教程

    原文链接:https://www.runoob.com/xpath/xpath-syntax.html XPath 术语 XPath 节点 七种类型:在 XPath 中,有七种类型的节点:元素.属性. ...

  10. 81-Gator Oscillator,加多摆动指标.(2015.7.1)

    Gator Oscillator 加多摆动指标 Oscillator,加多摆动指标.(2015.7.1)" title="81-Gator Oscillator,加多摆动指标.(2 ...