#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. java实现将资源文件转化成sql语句导入数据库

    文档结构

  2. hdu 4521 小明系列问题——小明序列(线段树 or DP)

    题目链接:hdu 4521 本是 dp 的变形,却能用线段树,感觉好强大. 由于 n 有 10^5,用普通的 dp,算法时间复杂度为 O(n2),肯定会超时.所以用线段树进行优化.线段树维护的是区间内 ...

  3. iOS——MVVM设计模式

    一.典型的iOS构架——MVC 在典型的MVC设置中,Model呈现数据,Vie呈现用户界面,而ViewController调节它两者之间的交互. 虽然View和View Controller是技术上 ...

  4. AngularJS中service,factory,provider的区别(转载:http://my.oschina.net/tanweijie/blog/295067)

    目录[-] 一.service引导 二.service 1.factory() ‍2.service()‍ ‍3.provider()‍‍ 一.service引导 刚开始学习Angular的时候,经常 ...

  5. openfire消息通知推送

    package cn.zsmy.utils.openfire; import java.io.BufferedReader; import java.io.InputStreamReader; imp ...

  6. mysql ERROR 1044 (42000): Access denied for user ''@'localhost' to database

    新安装的mysql密码是空的. ./mysql -u root -p use mysql SELECT `Host`,`User` FROM user; UPDATE user SET `Host` ...

  7. Css3_必备10个东西

    1.边框圆角(Border Radiuas) 这个是我们在平常很常用的吧,以前我在用div圆角的时候,特别特别的痛苦,不管是用CSS来画圆角,还是用图片来画圆角都不那么容易,但是现在好了,在CSS3中 ...

  8. 闹钟--alarmManager

    1.AlarmManager,顾名思义,就是“提醒”,是Android中 常用的一种系统级别的提示服务,在特定的时刻为我们广播一个指定的Intent.简单的说就是我们设定一个时间,然后在该时间到来 时 ...

  9. 注意64位整形,int64,long long

    在Xplorer中编译运行: int64_t  mask = 0xffffffffffffffffLL; if((j+64)>width) { printf("%x %d " ...

  10. [转]Android各大网络请求库的比较及实战

    自己学习android也有一段时间了,在实际开发中,频繁的接触网络请求,而网络请求的方式很多,最常见的那么几个也就那么几个.本篇文章对常见的网络请求库进行一个总结. HttpUrlConnection ...