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 ...
随机推荐
- [USACO09MAR]Cleaning Up
题目大意: 给你一个长度为n的序列a,你可以将其分为若干段,最终的答案为每一段不同数个数的平方和. 思路: 不难想到一个O(n^2)的DP: f[i]=min{f[j]+cnt(j,i)^2} 考虑一 ...
- 在React组件unmounted之后setState的报错处理
最近在做项目的时候遇到一个问题,在 react 组件 unmounted 之后 setState 会报错.我们先来看个例子, 重现一下问题: class Welcome extends Compone ...
- Vue.js常用指令汇总(v-if//v-show//v-else//v-for//v-bind//v-on等)
有时候指令太多会造成记错.记混的问题,所以本文在记忆的时候会采用穿插记忆的方式,交叉比对,不易出错. 本文主要讲了一下六个指令: v-if//v-show//v-else//v-for//v-bind ...
- 从头认识java-14.4 Java提供的数组的有用功能(2)
接着上一章节,我们继续介绍Java提供的数组的有用功能. 3.元素的对照Comparator package com.ray.ch14; import java.util.Arrays; import ...
- 初步了解更新锁(U)与排它锁(X)
一直没有认真了解UPDATE操作的锁.近期在MSDN论坛上看到一个问题,询问堆表更新的死锁问题,问题非常easy,有相似这种表及数据: CREATE TABLE dbo.tb( c1 int, ...
- Go语言格式化字符
https://github.com/polaris1119/The-Golang-Standard-Library-by-Example/blob/master/chapter01/01.3.md
- 单点登录cas常见问题(四) - ticket有哪些存储方式?
配置文件ticketRegistry.xml负责配置ticket的存储方式,registry是注冊表,登记薄的意思 经常使用的存储方式包含 1.DefaultTicketRegistry:默认的.存储 ...
- react-native 中使用 mobx
1. 介绍 1.1. 原理 React的render是 状态 转化为树状结构的渲染组件的方法而MobX提供了一种存储,更新 状态 的方法React 和 MobX都在优化着软件开发中相同的问题.Reac ...
- Ubuntu升级出现/boot空间不足解决(转)
经常升级Linux内核,导致更新时警告/boot分区空间不足.这是以为多次升级内核后,导致内核版本太多,清理一下没用的内核文件就行了.命令如下: zht@zht-Ubuntu:~$ dpkg -l ' ...
- C连接MySql
连接数据库connect.c #include <stdio.h> #include <mysql/mysql.h> int main() { //MYSQL句柄 MYSQL ...