Robot Motion - poj 1573
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 11269 | Accepted: 5486 |
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 <iostream>
#include<string.h>
using namespace std; int main() {
int row,col,x,y; int pos[][];
char ins[][];
int step;
int flag=-;
cin>>row>>col>>x;
while(row&&col&&x){
memset(pos,,sizeof(int)*);
y=;
step=;
flag=-;
for(int i=;i<row;i++){
for(int j=;j<col;j++){
cin>>ins[i][j];
}
}
pos[y-][x-]=;
for(int i=;i<row*col;i++){
switch(ins[y-][x-]){
case 'N':
y--;
break;
case 'E':
x++;
break;
case 'S':
y++;
break;
case 'W':
x--;
break;
} if(y>row||y<||x>col||x<){
flag=;
break;
}else if(pos[y-][x-]!=){
flag=;
break;
}else{
++step;
pos[y-][x-]=step;
} }
if(flag==){
cout<<step<<" step(s) to exit"<<endl;
}else{
cout<<(pos[y-][x-]-)<<" step(s) before a loop of "<<(step-pos[y-][x-]+)<<" step(s)"<<endl;
}
cin>>row>>col>>x;
}
return ;
}
Robot Motion - poj 1573的更多相关文章
- 模拟 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 ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- 【POJ - 1573】Robot Motion
-->Robot Motion 直接中文 Descriptions: 样例1 样例2 有一个N*M的区域,机器人从第一行的第几列进入,该区域全部由'N' , 'S' , 'W' , 'E' ,走 ...
- POJ 1573:Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11324 Accepted: 5512 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 ...
随机推荐
- JD
General Description: The role is responsible for China COE Operations Team’s data and cost analysis, ...
- [BZOJ 1509] 逃学的小孩
Link: BZOJ 1509 传送门 Solution: 一开始受样例影响又犯了想当然的毛病……图中的C点不一定在直径上! 3次$dfs$求出树的直径及直径的两个端点$rt1,rt2$到每个点的距离 ...
- iOS音频的后台播放 锁屏
初始化AudioSession和基本配置 音频播放器采用的AVPlayer ,在程序启动的时候需要配置AudioSession,AudioSession负责应用音频的设置,比如支不支持后台,打断等等, ...
- Spring/Spring MVC/Spring Boot实现跨域
说明:Spring MVC和Spring Boot其实用的都是同一套. CORS介绍请看这里:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Acc ...
- 【Linux】CentOS7上设置快捷键 随时补充
---------------------------------------------------------------------------------------------------- ...
- httpd.conf详细解释
httpd.conf详解 http://www.php100.com/html/webkaifa/apache/2009/0418/1192.html
- depth linear
float ConvertDepth( float depthFromTex, float4 cameraParams ){ const float near = cameraParams.z; co ...
- ES6中的Map集合(与java里类似)
Set类型可以用来处理列表中的值,但是不适用于处理键值对这样的信息结构.ES6也添加了Map集合来解决类似的问题 一.Map集合 JS的对象(Object),本质上是键值对的集合(Hash结构),但是 ...
- Win7系统管理员设置了系统策略,禁止进行此安装,怎么办
系统管理员设置了系统策略,禁止进行此安装,怎么办 最佳答案 尝试方法一: windows开始菜单,运行里面输入gpedit.msc打开组策略, 在"计算机配置"→管理模板→ ...
- 【MVC5】使用Autofac实现依赖注入
1.安装Autofac 在Package Manager Console执行如下命令: Install-Package AutofacInstall-Package Autofac.Mvc5 2.追加 ...