UVa, 10452 Marcus
来源:互联网 发布:淘宝上望远镜是真的 编辑:程序博客网 时间:2024/05/12 05:41
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
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;
/////////////////
const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
const char a[8]={'@','I','E','H','O','V','A','#'};
// 0 1 2 3 4 5 6 7
class Marcus{
private:
void dfs(int x,int y);
bool visit[1000][1000];
//vector<string>land;
char mapl[1000][1000];
int row,column;
int x,y;
int c;
public:
void initial();
void readcase();
void computing();
void outresult();
void outland();
};
void Marcus::initial(){
memset(mapl,0,sizeof(mapl));
memset(visit,0,sizeof(visit));
c=0;
}
void Marcus::readcase(){
cin>>row>>column;
//cout<<a[0]<<a[7];
//string ch;
for(int i=1;i<=row;i++){
for(int j=1;j<=column;j++){
cin>>mapl[i][j];
//land.push_back(ch);
}
}
}
void Marcus::computing(){
for(int i=1;i<=row;i++){
for(int j=1;j<=column;j++){
if(mapl[i][j]==a[0]){
x=i;y=j;
//cout<<x<<y<<endl;
mapl[i][j]=true ;
c++;
//cout<<c;
}
}
}
dfs(x,y);
}
void Marcus::dfs(int x, int y){
if( mapl[x][y+1] == a[c] && !visit[x][y+1]&&c<8){
printf("right");
if(c<7)printf(" ");
visit[x][y+1]=true;
c++;
dfs(x,y+1);
}
if( mapl[x][y-1] == a[c] && !visit[x][y-1]&&c<8){
printf("left");
if(c<7)printf(" ");
visit[x][y-1]=true;
c++;
dfs(x,y-1);
}
if( mapl[x-1][y] == a[c] && !visit[x-1][y]&&c<8 ){
printf("forth");
if(c<7)printf(" ");
visit[x-1][y]=true;
c++;
dfs(x-1,y);
}
//if( mapl[x][y-1] == a[c] && !visit[x][y-1] ) c++;dfs(x,y-1);
}
void Marcus::outland(){
for(int i=1;i<=row;i++){
for(int j=1;j<=column;j++){
cout<<mapl[i][j];
}
// cout<<land[i]<<endl;
cout<<endl;
}
}
////////////////////////////////////////////
int main(){
int n;
Marcus ma;
cin>>n;
while(n--){
ma.initial();
ma.readcase();
ma.computing();
//ma.outresult();
//ma.outland();
cout<<endl;
}
return 0;
}
- UVa, 10452 Marcus
- uva 10452 Marcus
- UVa 10452 - Marcus
- UVa 10452 - Marcus
- UVA 10452 Marcus
- UVA 10452 Marcus, help!( DFS )
- UVa10452 - Marcus
- Marcus McNeill's leverage
- dfs-Marcus, help!-uva10452
- Marcus在召集PHP开发工具的志愿者
- uva 10452
- O'Reilly数据秀播客|Adam Marcus谈智能系统和人工辅助计算
- 视频出炉 | LeCun、Marcus激辩AI是否需要类似人类的认知能力
- Yann LeCun vs Gary Marcus:AI 学习的未来更多取决于先天还是后天?
- uva
- UVA
- UVA
- UVA
- Ubuntu下的PHP安装CURL组件
- 初学opencv-显示图片的简单应用
- iOS控件属性总结(二)
- c++拷贝构造函数的调用时机
- 【转载于腾讯大讲堂】如何进行字体结构设计
- UVa, 10452 Marcus
- 用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出
- 按模版比例生成缩略图
- php array key 的存储规则
- Yaroslav and Time (简单最短路)
- Google经典面试题选录
- ruby进行http请求头设置及获取
- RobHess的SIFT源码分析:kdtree.h和kdtree.c文件
- 主机字节序 大端小端