题目链接:http://acm.hust.edu.cn/vjudge/contest/124435#problem/J

密码:acm

  1.  
  2.  
  1. Sample Input
  2.  
  3. NEESWE
  4. WWWESS
  5. SNWWWW
  6.  
  7. SESWE
  8. EESNW
  9. NWEEN
  10. EWSEN
  11.  
  12. Sample Output
  13. step(s) to exit
  14. step(s) before a loop of step(s)

分析:

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <stdlib.h>
  6. #include<queue>
  7. #include<math.h>
  8. using namespace std;
  9.  
  10. #define N 1001
  11. char s[N][N];
  12. int a[N][N],b[N][N];
  13.  
  14. int main()
  15. {
  16. int n,m,c,ans;
  17. while(scanf("%d%d%d",&n,&m,&c),n+m+c)
  18. {
  19. memset(a,,sizeof(a));
  20. memset(b,,sizeof(b));
  21. ans=;
  22.  
  23. for(int i=;i<=n;i++)
  24. scanf("%s",s[i]);
  25.  
  26. int i=;
  27. int j=c-;///字符串里面从零开始记录的,老是忘~~~~(>_<)~~~~
  28. while(1)
  29. {
  30. b[i][j]=;
  31. if(s[i][j]=='N')
  32. i=i-;
  33. else if(s[i][j]=='S')
  34. i=i+;
  35. else if(s[i][j]=='E')
  36. j=j+;
  37. else
  38. j=j-;
  39. ans++;
  40. if(b[i][j])
  41. {
  42. printf("%d step(s) before a loop of %d step(s)\n",a[i][j],ans-a[i][j]);
  43. break;
  44. }
  45. a[i][j]=ans;
  46.  
  47. if(i==||j==-||i==n+||j==m)
  48. {
  49. printf("%d step(s) to exit\n",ans);
  50. break;
  51. }
  52. }
  53. }
  54. return ;
  55. }

多校 Robot Motion的更多相关文章

  1. poj1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12507   Accepted: 6070 Des ...

  2. Robot Motion(imitate)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11065   Accepted: 5378 Des ...

  3. 模拟 POJ 1573 Robot Motion

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

  4. POJ 1573 Robot Motion(BFS)

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

  5. Robot Motion 分类: POJ 2015-06-29 13:45 11人阅读 评论(0) 收藏

    Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11262 Accepted: 5482 Descrip ...

  6. POJ 1573 Robot Motion

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

  7. Poj OpenJudge 百练 1573 Robot Motion

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

  8. POJ1573——Robot Motion

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

  9. hdoj 1035 Robot Motion

    Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

随机推荐

  1. caffe层解读系列-softmax_loss

    转自:http://blog.csdn.net/shuzfan/article/details/51460895 Loss Function softmax_loss的计算包含2步: (1)计算sof ...

  2. nginx启动,重启,关闭

    1.nginx启动: a.     /usr/path/sbin/nginx -c [/etc/path/nginx.conf] 中括号中为指定加载的配置文件,不指定则加载默认配置文件 b.     ...

  3. 4. JavaScript 控制语句

    1. If...Else 语句 1.1 条件语句if /* 格式: 1. if ... 2. if ... else ... 3. if ... else if .... else 4. switch ...

  4. iOS 视图控制器生命周期

    1.init: 2.viewDidLoad: 3.viewWillAppear: 4.viewDidAppear: 5.viewWillDisappear; 6.viewDidDisappear

  5. JavaScript Function arguments.callee caller length return

    一.Function 函数是对象,函数名是指针. 函数名实际上是一个指向函数对象的指针. 使用不带圆括号的函数名是访问函数指针,并非调用函数. 函数的名字仅仅是一个包含指针的变量而已.即使在不同的环境 ...

  6. JavaScript 操作符 变量

    一.操作符: 一元操作符 递增操作符 递减操作符 分为 前置型(--a    ++a) 和 后置型 (a--    a++) 区别如下: var a = 3,b=6; c = --a +b; //c= ...

  7. js通过keyCode值判断单击键盘上某个键,然后触发指定的事件

    当单击按键时触发事件    document.onkeydown = function (e) {             e = e || event;             if (e.keyC ...

  8. C语言_基础代码_01

    #include<stdio.h> #include<stdlib.h> #define BUFFERSIZE 1024/*允许处理的最长行有1024个字符*/ /*编译环境v ...

  9. QTP使用小技巧

    1.创建action template.     当希望在每一个新建action时都增加一些头部说明,比如作者.创建日期.说明等,用action template     来实现最简单快捷.      ...

  10. c专家编程---优先级规则

    对于一些复杂的类型组合,总是搞不明白,今天阅读了“优先级规则”这块,有了进一步的理解,特将规则记在此处,供自己学习查询使用. 优先级规则: A.声明从它的名字开始读取,然后按照优先级顺序依次读取 B. ...