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 ...
随机推荐
- SQL Server 2008 R2 SP3 and SQL Server 2008 SP4 are now available!
时间 2014-10-02 00:00:00 SQL Server Team Blog 原文 http://blogs.technet.com/b/dataplatforminsider/arc ...
- linux命令行翻页
在linux上面执行命令,若命令太多屏幕显示不完,通过Shift+pageup/pageDown来查看. putty连接linux后执行就不存在这个问题.
- 纯CSS实现网站常用的五角星评分和分数展示交互效果
最近做的一个项目涉及到评分和展示分数的模块,UI设计师也给了几个切好的图片,实现五角星评分方式很多,本质爱折腾的精神和对性能追求以及便于维护的考虑,搜集和尝试了很多方式,最终采用了纯css驱动的实现方 ...
- Chrome的开发必备小技巧
谷歌Chrome,是当前最流行且被众多web开发人员使用的浏览器.最快六周就更新发布一次以及伴随着它不断强大的开发组件,使得Chrome成为你必备的开发工具.例如,在线编辑CSS,console以及d ...
- androd 获得wifi列表
AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xm ...
- Object 类中的 equals方法
1 相等与同一 如果两个对象具有相同的类型以及相同的属性值,则称这两个对象相等.如果两个引用对象指的是同一个对像,则称这两个变量同一.Object类中定义的equals 函数原型为:public bo ...
- 为什么输入shutdown -h -t会报错:command not fount
如果是直接用普通用户($)的身份进行输入[user@localhost ~]$ shutdown -h -t 是不能执行,因为普通用户没有关闭机器的权限. 然而直接使用[user@localhost ...
- 2017.7.1 nginx反向代理服务器域名解析配置(已验证可使用)
下载地址:http://learning.happymmall.com/ 前提:ftpserver已经开启,并且设置为: 1.获得安装文件 2.修改配置文件 2.1 修改conf/nginx.conf ...
- Java Servlet 技术简介 from:IBM Dev
点评:讲的没有太听懂. from: http://www.ibm.com/developerworks/cn/education/java/j-intserv/index.html#resources
- Poj 4227 反正切函数的应用
Description 反正切函数可展开成无穷级数,有例如以下公式 (当中0 <= x <= 1) 公式(1) 使用反正切函数计算PI是一种经常使用的方法.比如,最简单的计算PI的方法: ...