1. #define ONLINE_JUDGE
  2. #include<cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int A,B,sx,sy;
  8. char maz[101][101];
  9. int vis[101][101];
  10. const int dx[4]={0,1,0,-1};
  11. const int dy[4]={-1,0,1,0};
  12.  
  13. int dir(char ch){
  14. if(ch=='N')return 0;
  15. else if(ch=='E')return 1;
  16. else if(ch=='S')return 2;
  17. return 3;
  18. }
  19. void print(int step){
  20. for(int s=1;s<step;s++){
  21. for(int i=0;i<A;i++){
  22. for(int j=0;j<B;j++){
  23. if(vis[j][i]==s){
  24. printf("vis[%d][%d]:%d\n",j,i,vis[j][i]);
  25. }
  26. }
  27. }
  28. }
  29. }
  30. void solve(){
  31. memset(vis,0,sizeof(vis));
  32. sx--;sy=0;
  33. int step=0;
  34. int fx,fy;
  35. while(!vis[sy][sx]&&sx>=0&&sx<A&&sy>=0&&sy<B&&++step){
  36. fx=sx;fy=sy;
  37. vis[sy][sx]=step;
  38. sx=dx[dir(maz[fy][fx])]+fx;
  39. sy=dy[dir(maz[fy][fx])]+fy;
  40. }
  41. if(sx<0||sy<0||sx>=A||sy>=B)printf("%d step(s) to exit\n",step);
  42. else {
  43. printf("%d step(s) before a loop of %d step(s)\n",vis[sy][sx]-1,step+1-vis[sy][sx]);
  44. }
  45. }
  46. int main(){
  47. #ifndef ONLINE_JUDGE
  48. freopen("output.txt","w",stdout);
  49. #endif // ONLINE_JUDGE
  50. while(scanf("%d%d%d",&B,&A,&sx)==3&&A&&B){
  51.  
  52. for(int i=0;i<B;i++)scanf("%s",maz[i]);
  53. solve();
  54. }
  55. return 0;
  56. }

  

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. [转载] 360分布式存储系统Bada的设计和应用

    原文: http://mp.weixin.qq.com/s?__biz=MzAwMDU1MTE1OQ==&mid=208931479&idx=1&sn=1dc6ea4fa28a ...

  2. 对sizeof的思考

    一.sizeof的特点(与strlen比较) 1.sizeof是运算符,strlen是函数,这意味着编译程序在编译的时候就把sizeof计算过了,所以sizeof(x)可以用来定义数组维数. 例如 i ...

  3. 学习日记day 10 : JavaScript秋风扫落叶第一期

    1:实参形参概念清晰化 注意调用,声明和定义的区别. 调用发过去的都是实参,声明和定义中使用的都是形参. 例子: funcOperate (int a);  //这是函数声明:参数都是形参: int ...

  4. 花神的数论题(数位dp)

    规定sum[i] 为i里面含1的个数 ,求从1-N sum[i]的乘积. 数为64位内的,也就是sum[i]<=64的,这样可以dp求出1-N中含k个1的数有多少个,快速幂一下就可以了. 有个地 ...

  5. XML 解析器

    所有现代浏览器都内建了供读取和操作 XML 的 XML 解析器.解析器把 XML 转换为 XML DOM 对象 - 可通过 JavaScript 操作的对象. 解析 XML 文档为DOM对象 方法一: ...

  6. asp.net 柱形图

    在vs中,如果要使用柱形图,我们大多数使用第三方提供的插件,所以必须要引用样式,这里我使用的是Highcharts-4.1.9插件,百度一下就可以下载到. 关键的js代码: <script sr ...

  7. iOS开发之 Xcode 一个工程 Project 添加多个 target

    http://www.360doc.com/content/14/1203/11/19119980_430056974.shtml# 根据项目需求,同一个工程有多个版本,每个版本只有细微的不同.所以, ...

  8. jQuery动态加载脚本 $.getScript();

    jQuery.getScript("/path/to/myscript.js", function(data, status, jqxhr) {       /*          ...

  9. 转: 浅谈C/C++中的指针和数组(二)

    转自:http://www.cnblogs.com/dolphin0520/archive/2011/11/09/2242419.html 浅谈C/C++中的指针和数组(二) 前面已经讨论了指针和数组 ...

  10. Windows 调色板

    目录 第1章调色板    1 1.1 为什么要使用调色板    1 1.2 使用调色板    2 1.2.1 创建逻辑调色板    2 1.2.2 使用    3 1.2.3 销毁逻辑调色板    4 ...