#define ONLINE_JUDGE
#include<cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int A,B,sx,sy;
char maz[101][101];
int vis[101][101];
const int dx[4]={0,1,0,-1};
const int dy[4]={-1,0,1,0}; int dir(char ch){
if(ch=='N')return 0;
else if(ch=='E')return 1;
else if(ch=='S')return 2;
return 3;
}
void print(int step){
for(int s=1;s<step;s++){
for(int i=0;i<A;i++){
for(int j=0;j<B;j++){
if(vis[j][i]==s){
printf("vis[%d][%d]:%d\n",j,i,vis[j][i]);
}
}
}
}
}
void solve(){
memset(vis,0,sizeof(vis));
sx--;sy=0;
int step=0;
int fx,fy;
while(!vis[sy][sx]&&sx>=0&&sx<A&&sy>=0&&sy<B&&++step){
fx=sx;fy=sy;
vis[sy][sx]=step;
sx=dx[dir(maz[fy][fx])]+fx;
sy=dy[dir(maz[fy][fx])]+fy;
}
if(sx<0||sy<0||sx>=A||sy>=B)printf("%d step(s) to exit\n",step);
else {
printf("%d step(s) before a loop of %d step(s)\n",vis[sy][sx]-1,step+1-vis[sy][sx]);
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE
while(scanf("%d%d%d",&B,&A,&sx)==3&&A&&B){ for(int i=0;i<B;i++)scanf("%s",maz[i]);
solve();
}
return 0;
}

  

POJ 1573 Robot Motion 模拟 难度:0的更多相关文章

  1. 模拟 POJ 1573 Robot Motion

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

  2. POJ 1573 Robot Motion(模拟)

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

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

                                                                                                         ...

  4. POJ 1573 Robot Motion(BFS)

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

  5. POJ 1573 Robot Motion

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

  6. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

  7. poj 1573 Robot Motion_模拟

    又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...

  8. Poj OpenJudge 百练 1573 Robot Motion

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

  9. [ACM] hdu 1035 Robot Motion (模拟或DFS)

    Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...

随机推荐

  1. phpStorm如何在Console控制台执行php文本,而不是浏览器中

    如何在Console控制台执行php文本 phpStorm默认会在浏览器中执行脚本 默认的配置 配置PHP脚本 扩展,配置项目运行

  2. ORA-32004 参数设置过时的解决办法

    启动时报错: 查看日志: view /opt/oracle11g/app/db/diag/rdbms/yldev/yldev/trace/alert_yldev.log 原来是plsql_debug ...

  3. PHP 链式操作

    所谓链式操作最简单的理解就是 操作完毕之后再返回对象$this 想必大家工作中基本都快用烂了得东西. 下面就是一个链式操作MYSQL数据库类. 最常见的链式操作 每一个方法操作之后,返回一个对象,直到 ...

  4. MyBatis——实现关联表查询

    原文:http://www.cnblogs.com/xdp-gacl/p/4264440.html 一.一对一关联 1.1.提出需求 根据班级id查询班级信息(带老师的信息) 1.2.创建表和数据 创 ...

  5. x+y = ((x&y)<<1) + (x^y) 证明

    法一:我们考虑x,y在二进制表示时候,按位相加其中第i位xi+yi = ((xi&yi)<<1) + (xi^yi)其中(xi&yi)<<1表示当xi和yi都是 ...

  6. linux gcc 编译动态类库(.so)和静态类库(.a)

    linux gcc 编译动态类库(.so)和静态类库(.a) 我的编译环境 ubuntu desktop 16.04 一:测试代码 测试有3个文件:AB.h,AB.c,test.c //AB.h vo ...

  7. java 字符串 转码

    //xmlStr 为需要转码的字符串 UTF-8 可改为不同的编码格式 如:GBK //亲测可用 仅供参考 String xmlStrs=""; try{ xmlStrs=new ...

  8. ARPG客户端中场景对象体系设计

    一.场景对象体系 二.场景对象生命周期管理 场景对象的生命周期,不适合采用原始的c++管理方式, 即由使用者自己负责删除.而应该采用引用计数方式, 自动负责删除. 采用引用计数方式, 目前用法比较广的 ...

  9. 有关mipmaps

    Mipmaps的作用是什么,仅仅是为了使屏幕三角形和纹理三角形的差异变小?有没有以空间换时间的理念? Mipmaps在生成一系列小的纹理样本时, 是如何从原始纹理采样的?即如何生成这些小的纹理样本.

  10. hibernate4.3.10使用注解映射方式样例

    1.调用例子 import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.boot.re ...