Robot Motion
Description

A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are
N north (up the page)
S south (down the page)
E east (to the right on the page)
W west (to the left on the page)
For example, suppose the robot starts on the north (top) side of Grid 1 and starts south (down). The path the robot follows is shown. The robot goes through 10 instructions in the grid before leaving the grid.
Compare what happens in Grid 2: the robot goes through 3 instructions only once, and then starts a loop through 8 instructions, and never exits.
You are to write a program that determines how long it takes a robot to get out of the grid or how the robot loops around.
Input
Output
Sample Input
3 6 5
NEESWE
WWWESS
SNWWWW
4 5 1
SESWE
EESNW
NWEEN
EWSEN
0 0 0
Sample Output
10 step(s) to exit
3 step(s) before a loop of 8 step(s)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char s[][];
int i,j,m,n,a,p[][];
while(scanf("%d %d %d%*c",&m,&n,&a)&&m&&n&&a)
{
memset(p,,sizeof(p));
for(i=; i<m; i++)
{
for(j=; j<n; j++)
scanf("%c",&s[i][j]);
getchar();
}
j=a-;
i=;
p[i][j]=;
while()
{
if(s[i][j]=='N')
{
if(i-<)
{
printf("%d step(s) to exit\n",p[i][j]);
break;
}
else if(p[i-][j])
{
printf("%d step(s) before a loop of %d step(s)\n",p[i-][j]-,p[i][j]+-p[i-][j]);
break;
}
else
{
p[i-][j]=p[i][j]+;
i--;
continue;
}
}
else if(s[i][j]=='S')
{
if(i+==m)
{
printf("%d step(s) to exit\n",p[i][j]);
break;
}
else if(p[i+][j])
{
printf("%d step(s) before a loop of %d step(s)\n",p[i+][j]-,p[i][j]+-p[i+][j]);
break;
}
else
{
p[i+][j]=p[i][j]+;
i++;
continue;
}
}
else if(s[i][j]=='W')
{
if(j-<)
{
printf("%d step(s) to exit\n",p[i][j]);
break;
}
else if(p[i][j-])
{
printf("%d step(s) before a loop of %d step(s)\n",p[i][j-]-,p[i][j]+-p[i][j-]);
break;
}
else
{
p[i][j-]=p[i][j]+;
j--;
continue;
}
}
else if(s[i][j]=='E')
{
if(j+==n)
{
printf("%d step(s) to exit\n",p[i][j]);
break;
}
else if(p[i][j+])
{
printf("%d step(s) before a loop of %d step(s)\n",p[i][j+]-,p[i][j]+-p[i][j+]);
break;
}
else
{
p[i][j+]=p[i][j]+;
j++;
continue;
}
}
}
}
return ;
}
Robot Motion的更多相关文章
- poj1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12507 Accepted: 6070 Des ...
- Robot Motion(imitate)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11065 Accepted: 5378 Des ...
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
- POJ 1573 Robot Motion(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- Robot Motion 分类: POJ 2015-06-29 13:45 11人阅读 评论(0) 收藏
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11262 Accepted: 5482 Descrip ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- POJ1573——Robot Motion
Robot Motion Description A robot has been programmed to follow the instructions in its path. Instruc ...
- hdoj 1035 Robot Motion
Robot Motion Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU-1035 Robot Motion
http://acm.hdu.edu.cn/showproblem.php?pid=1035 Robot Motion Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- javascript,jquery(闭包概念)(转)
偶尔听人说javascript闭包,让我联想起以前学编译原理和数字逻辑里讲的闭包,以前上课讲的闭包很难懂,而且含有递归的意思在里面,现在不想再查看里面的闭包概念. 但javascript我是经常要用, ...
- 使用vi是方向键变乱码 退格键不能使用的解决方法
一.编辑/etc/vim/vimrc.tiny 由于/etc/vim/vimrc.tiny的拥有者是root用户,所以要在root的权限下对这个文件进行修改.很简单,这个文件里面的倒数第二句话是“se ...
- Android Activity横竖屏转换的生命周期
新创建一个Activity,用来此次测试. 先贴代码 package com.hugo.apj.activitylifetest; import android.support.v7.app.AppC ...
- Python之路【第十一篇】:CSS --暂无内容-待更新
Python之路[第十一篇]:CSS --暂无内容-待更新
- PHP 解决未定义变量报错
在PHP中 有时候会出现 Notice: Undefined index: sid in D:\Apache Group\Apache2\htdocs\php_mobile\mobile\chao\s ...
- java中怎么进行字符串替换?
String str = "test.doc"; String newStr = str.replaceAll("doc","html");
- ORACLE用户管理方式下备份数据和复制数据库
首先要明确的是,oracle数据库的备份可以分为逻辑备份和物理备份. 逻辑备份的是通过数据导出对数据进行备份,主要方式有老式的IMP/EXP和数据泵灯方式.适合变化较少的数据库,而 ...
- iOS 事件处理机制与图像渲染过程(转)
iOS 事件处理机制与图像渲染过程 iOS RunLoop都干了什么 iOS 为什么必须在主线程中操作UI 事件响应 CALayer CADisplayLink 和 NSTimer iOS 渲染过程 ...
- JavaScript - 测试 jQuery
测试 JavaScript 框架库 - jQuery 引用 jQuery 如需测试 JavaScript 库,您需要在网页中引用它. 为了引用某个库,请使用 <script> 标签,其 s ...
- JS特殊符号
反斜杠用来在文本字符串中插入省略号.换行符.引号和其他特殊字符. 代码 输出 \' 单引号 \" 双引号 \& 和号 \\ 反斜杠 \n 换行符 \r 回车符 \t 制表符 \b 退 ...