原题大意:原题链接

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

此题虽然属于水题,但是完全独立完成而且直接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. hdu 3336:Count the string(数据结构,串,KMP算法)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. Appium使用Python运行appium测试的实例

    Appium使用Python运行appium测试的实例 一.  Appium之介绍 https://testerhome.com/topics/8038 详情参考--https://testerhom ...

  3. Spring_day04--SSH框架整合过程

    SSH框架整合过程 第一步 导入jar包 第二步 搭建struts2环境 (1)创建action,创建struts.xml配置文件,配置action (2)配置struts2的过滤器 第三步 搭建hi ...

  4. 编译OSG_FBX插件

    安装FBX的SDK,例如C:\Program Files\Autodesk\FBX\FBX SDK\2017.1\ 在CMake配置lib库路径的时候,使用 C:\Program Files\Auto ...

  5. phpstrom如何定义文件打开的方式

    今天想vue结合PHP来小写一段代码,但是发现自己把vue的文件放进去,会显示text文本,在刚开始的时候,编辑器会提示我们以什么格式打开,我没在意的选择了text,结果悲催了,那么在设置里面的哪个选 ...

  6. android-修改TextView中部分文字的颜色

    :

  7. node npm

    node.js -npm 查看npm版本号$ npm -v 全局安装npm$ npm install npm -g 安装模块$ npm install <module name> --本地 ...

  8. JAVAWEB基础模块开发顺序与数据访问对象实现类步骤

    一.模块的开发的顺序 1. 定义数据表 2. 新建模型类 3. 新建"add.jsp" 4. 实现AddServlet中的doGet()方法 5. 定义Dao.Service接口 ...

  9. 通过/dev/mem只能访问高端内存以下的内核线性地址空间

    http://blog.chinaunix.net/uid-20564848-id-74706.html   </proc/iomem和/proc /ioports对应的fops> < ...

  10. windows accounts

    Some built-in groups are used for management purposes. You control which > users belong to these ...