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 ...
随机推荐
- Context3D的setProgramConstantsFromMatrix使用时需注意的事项
setProgramConstantsFromMatrix() public function setProgramConstantsFromMatrix(programType:String, fi ...
- 在C#中用RX库和await来实现直观的状态机
在程序的设计过程中,我们经常会遇到一些需要使用状态机的场景,相信状态机的编写和维护是令每一个程序员都非常头大的事情.到了C# 5.0后,由于引进了await语法糖,我们可以通过await和Reacti ...
- 设置并删除Dreamweaver自动生成的_notes文件夹
在使用Dreamweaver做项目时站点下面的每个文件夹里面都会自动生成一个_notes文件夹,删除之后马上又会再次生成.最近做项目时,有童鞋一不小心把所有的_notes文件夹全部存回到SVN上面了, ...
- IMAP 命令
最近学习了一下IMAP命令,现在也算总结一下学习的东西,先说说IMAP命令,如果你使用的是163.126邮箱,反正是网易家的邮箱,那么这里就有很多坑要踩了,因为网易邮箱的特殊性,由于网易邮箱在中国占有 ...
- 由jtable浅谈vector<vector<Object>>的用法(转自a718515028的专栏)
以前只用过vector<Object> ,但是在做从数据库导出数据放到jtable中时,发现还有个vector<vector<Object>>的用法. 先说jta ...
- ElasticSearch _xpack角色管理
权限管理可以通过kibana的Management界面进行,本篇主要介绍的是通过命令进行,角色API使您能够在本机域中添加,删除和检索角色. 要使用此API,您必须至少具有manage_securit ...
- (总结)Linux下的暴力密码在线破解工具Hydra详解
(总结)Linux下的暴力密码在线破解工具Hydra详解 学习了:https://blog.csdn.net/yafeichang/article/details/53502869
- 10. 修改端口号【从零开始学Spring Boot】
转载:http://blog.csdn.net/linxingliang/article/details/51637017 spring boot 默认端口是8080,如果想要进行更改的话,只需要修改 ...
- git学习——查看提交历史
git log可以查看提交历史: 用-p选项展开显示每次提交的内容差异,用-2则仅显示最近两次的更新:git log -p -2 在-p选项后面使用--word-diff选项进行单词层面的对比.这其中 ...
- python 赋值 深浅拷贝
深浅拷贝 一.数字和字符串 对于 数字 和 字符串 而言,赋值.浅拷贝和深拷贝无意义,因为其永远指向同一个内存地址. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 impor ...