原题大意:原题链接

给出一个矩阵(矩阵中的元素均为方向英文字母),和人的初始位置,问是否能根据这些英文字母走出矩阵.(因为有可能形成环而走不出去)

此题虽然属于水题,但是完全独立完成而且直接1A还是很开心的

注意:对于形成环的情况则从进入环的交点处重新走一遍,记录步数即可

#include<cstdio>
#include<cstring>
int n,m,p;
bool vis[][];
char str[][];
bool can(int x,int y)
{
if(x<||x>n||y<||y>m||vis[x][y])
return false;
return true;
}
int main()
{
while(scanf("%d%d%d",&n,&m,&p),n|m|p){
memset(vis,,sizeof(vis));
getchar();
for(int i=;i<=n;i++){
for(int j=;j<=m;j++)
scanf("%c",&str[i][j]);
getchar();
}
int x=,y=p,step1=;
while(can(x,y)){
int px=x,py=y;
vis[px][py]=;
if(str[px][py]=='E')
{y++,step1++;}
else if(str[px][py]=='S')
{x++,step1++;}
else if(str[px][py]=='W')
{y--,step1++;}
else if(str[x][y]=='N')
{x--,step1++;}
}
if(vis[x][y]){
int step2=,ox=x,oy=y;
while(){
int px=x,py=y;
if(str[px][py]=='E')
{y++,step2++;}
else if(str[px][py]=='S')
{x++,step2++;}
else if(str[px][py]=='W')
{y--,step2++;}
else if(str[px][py]=='N')
{x--,step2++;}
if(x==ox&&y==oy){
printf("%d step(s) before a loop of %d step(s)\n",step1-step2,step2);
break;
}
}
}
else printf("%d step(s) to exit\n",step1);
}
}

PKU 1573 Robot Motion(简单模拟)的更多相关文章

  1. POJ 1573 Robot Motion(模拟)

    题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...

  2. poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】

                                                                                                         ...

  3. POJ1573(Robot Motion)--简单模拟+简单dfs

    题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...

  4. 模拟 POJ 1573 Robot Motion

    题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...

  5. POJ 1573 Robot Motion(BFS)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12856   Accepted: 6240 Des ...

  6. Poj OpenJudge 百练 1573 Robot Motion

    1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...

  7. POJ 1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12978   Accepted: 6290 Des ...

  8. POJ 1573 Robot Motion 模拟 难度:0

    #define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...

  9. poj1573&amp;&amp;hdu1035 Robot Motion(模拟)

    转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接: HDU:pid=1035">http://acm.hd ...

随机推荐

  1. hive经常使用命令

    hive经常使用命令 show tables; 列出hive里面全部数据表名 desc userProfile; 显示数据表userProfile的基本表字段及字段type desc extended ...

  2. MathType中空格个数怎么显示

    在使用Word文档的时候很时候用原软件自带的公式编辑器不是很好用,也不方法.MathType就是来解决这个问题的,但是一些用户在使用过程中发现不会看究竟输了多少空格,只能估摸大概.下面本MathTyp ...

  3. Oracle sqlldr命令

    今天别人的入库代码,看的真有点晕,最后看完才知道是用了sqlldr命令.哎...还是学艺不精啊,今后还是要多努力. 总结哈sqlldr命令:虽然大多是网上来的,自己要有体会嘛 !开源就是好啊. sql ...

  4. box-sizing在什么情况下会失效

    众所周知,box-sizing是将w3c盒模型与IE盒模型相互转换的利器,但是有时候也会失效,那么在什么情况下回失效呢,MD在没设置高度的时候回失效的透透的,所以一定记得需要转换的时候设置个高度!!!

  5. Struts入门(三)深入Struts用法讲解

    访问Servlet API Action搜索顺序 动态方法调用 指定多个配置文件 默认Action Struts 后缀 接收参数 处理结果类型 1.访问Servlet API 首先我们了解什么是Ser ...

  6. setTimeout 里 传递字符串代码报错

    js高程 第三版 p203 重点:超时调用的代码都是在全局作用域中执行的,因此函数中this 的值在非严格模 式下指向window 对象,在严格模式下是undefined. 不过这里仅仅解释前半句: ...

  7. 160330、Mybatis整合Spring

    转自csdn文章 http://haohaoxuexi.iteye.com/blog/1843309 Mybatis整合Spring 根据官方的说法,在ibatis3,也就是Mybatis3问世之前, ...

  8. HTML5跨平台开发环境配置

    http://hi.baidu.com/kuntakinte/item/1bbd3759b4901a3695eb050c

  9. oracle 归档空间满的解决办法

    问题现象: 通过命令提示符登陆数据库,一般提示“ora-03113:通信通道的文件结尾”错误,查看trace日志,可以看到详细信息.部分摘录如下(橙色部分给出了建议方案): Errors in fil ...

  10. LInux中ThreadInfo中的preempt_count字段

    最近看各种上下文,发现和ThreadInfo中的preemption字段密切,于是便调查了下. 看下Linux源码中的注释: /* * We put the hardirq and softirq c ...