POJ 1573
#include<iostream>
#include<stdio.h>
#define MAXN 15
using namespace std; char _m[MAXN][MAXN];
bool mark[MAXN][MAXN];
int record[MAXN][MAXN]; int r;
int c;
void dfs(int i,int j);
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int j;
int place;
while(cin>>r>>c>>place)
{
if(!r && !c && !place)
break;
-- place;
memset(mark,false,sizeof(mark));
// memset(record,0,sizeof(record));
for(i = ; i < r; ++ i)
{
for(j = ; j < c; ++ j)
{
record[i][j] = ;
}
}
for(i = ; i < r; ++ i)
{
for(j = ; j < c; ++ j)
{
cin>>_m[i][j];
}
}
record[][place] = ;
mark[][place] = true;
dfs(,place);
// for(i = 0; i < r; ++ i)
// {
// for(j = 0; j < c; ++ j)
// {
// cout<<record[i][j]<<" ";
// }
// cout<<endl;
// }
}
}
void fun_1(int num);
void fun_2(int num,int num_1);
void dfs(int i,int j)
{
int tem1;
int tem2;
if(_m[i][j] == 'E')
{
if(j + < c)
{
if(!mark[i][j+])
{
mark[i][j+] = true;
record[i][j+] += record[i][j];
dfs(i,j+);
return ;
}
else
{
fun_2(record[i][j+]-,record[i][j]-record[i][j+]+);
return ;
}
}
else
{
fun_1(record[i][j]);
return ;
}
}/////////////////////// if(_m[i][j] == 'S')
{
if(i + < r)
{
if(!mark[i+][j])
{
mark[i+][j] = true;
record[i+][j] += record[i][j];
dfs(i+,j);
return ;
}
else
{
fun_2(record[i+][j]-,record[i][j]-record[i+][j]+);
return ;
}
}
else
{
fun_1(record[i][j]);
return ;
}
}////////////////////////////// if(_m[i][j] == 'W')
{
if(j - >= )
{
if(!mark[i][j-])
{
mark[i][j-] = true;
record[i][j-] += record[i][j];
dfs(i,j-);
return ;
}
else
{
fun_2(record[i][j-]-,record[i][j]-record[i][j-]+);
return ;
}
}
else
{
fun_1(record[i][j]);
return ;
}
}/////////////////////////////////////////// if(_m[i][j] == 'N')
{
if(i - >= )
{
if(!mark[i-][j])
{
mark[i-][j] = true;
record[i-][j] += record[i][j];
dfs(i-,j);
return;
}
else
{
fun_2(record[i-][j]-,record[i][j]-record[i-][j]+);
return ;
}
}
else
{
fun_1(record[i][j]);
return ;
}
}
} void fun_1(int num)
{
cout<<num;
// if(num != 1)
cout<<" step(s) to exit"<<endl;
// else
// cout<<" step to exit"<<endl;
} void fun_2(int num,int num_1)
{
cout<<num;
// if(num != 1)
cout<<" step(s) before a loop of ";
// else
// cout<<" step before a loop of ";
cout<<num_1;
// if(num_1 != 1)
cout<<" step(s)"<<endl;
// else
// cout<<" step"<<endl;
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com
POJ 1573的更多相关文章
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
- POJ 1573 Robot Motion(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- POJ 1573 (13.10.11)
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- poj 1573 Robot Motion_模拟
又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- Robot Motion - poj 1573
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11269 Accepted: 5486 Description A ...
随机推荐
- hdu 2141 Can you find it?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Description Give you three sequ ...
- poj 2153 Rank List
原题链接:http://poj.org/problem?id=2153 简单题,map,平衡树均可.. map: #include<algorithm> #include<iostr ...
- Android清除本地数据缓存代码案例
Android清除本地数据缓存代码案例 直接上代码: /* * 文 件 名: DataCleanManager.java * 描 述: 主要功能有清除内/外缓存,清除数据库,清除shar ...
- Partition分组使用和行列转换
CREATE TABLE score ( name NVARCHAR(20), subject NVARCHAR(20), score INT ) --2.插入测试数据 INSERT INTO sco ...
- mac下163企业邮箱客户端的配置
一 添加账户 添加账户->添加其他邮件账户->输入电子邮件地址和密码.(全名随意起). 二 收件服务器和发件服务器的设置 收件服务器:pop.qiye.163. ...
- [转]UDP/TCP穿越NAT的P2P通信方法研究(UDP/TCP打洞 Hole Punching)
[转]UDP/TCP穿越NAT的P2P通信方法研究(UDP/TCP打洞 Hole Punching) http://www.360doc.com/content/12/0428/17/6187784 ...
- ubuntu14.04建立交叉编译环境, 注意事项
ubuntu14.04建立交叉编译环境, 注意事项 ~$ arm-linux-gcc/opt/FriendlyARM/toolschain/4.4.3/bin/arm-linux-gcc: 15: e ...
- Min Stack
Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constan ...
- 封装insertAfter、addClass、格式化时间
insertAfter,在JS节点操作中,并没有insertAfter方法,因此需要重新封装 function insertAfter(newEle,targetNode) { var oParent ...
- 十步!轻松搞定IIS+PHP环境
突然心血来潮想着自己一直使用Apache+php的模式,想要了解一下IIS+php的模式.说起来也算是九曲十八弯吧! 第一部分:以ISAPI.dll 扩展的形式 结果按照资料上面说的我就是找不到一个i ...