Robot Motion(imitate)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 11065 | Accepted: 5378 |
Description

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)
Source
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int row , col , o ;
char map[][] ;
int a[][] ;
int x , y ; void loop (char dir)
{
switch (dir)
{
case 'N' : printf ("%d step(s) before a loop of %d step(s)\n" , a[x][y] - , a[x + ][y] - a[x][y] + ) ; break ;
case 'E' : printf ("%d step(s) before a loop of %d step(s)\n" , a[x][y] - , a[x][y - ] - a[x][y] + ) ; break ;
case 'S' : printf ("%d step(s) before a loop of %d step(s)\n" , a[x][y] - , a[x - ][y] - a[x][y] + ) ; break ;
case 'W' : printf ("%d step(s) before a loop of %d step(s)\n" , a[x][y] - , a[x][y + ] - a[x][y] + ) ; break ;
}
}
void solve ()
{
x = , y = o ;
bool flag = ;
char temp ;
a[x][y] = ;
while (x >= && x <= row && y >= && y <= col) {
switch (map[x][y])
{
case 'N' : x-- ; if (a[x][y]) flag = ;
if (!flag)
a[x][y] = a[x + ][y] + ;
else
temp = 'N' ; break ;
case 'E' : y++ ; if (a[x][y]) flag = ;
if (!flag)
a[x][y] = a[x][y - ] + ;
else
temp = 'E' ; break ;
case 'S' : x++ ; if (a[x][y]) flag = ;
if (!flag)
a[x][y] = a[x - ][y] + ;
else
temp = 'S' ; break ;
case 'W' : y-- ; if (a[x][y]) flag = ;
if (!flag)
a[x][y] = a[x][y + ] + ;
else
temp = 'W' ; break ;
}
if (flag) {
loop (temp) ;
break ;
}
}
if (!flag)
printf ("%d step(s) to exit\n" , a[x][y] - ) ;
}
int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
while (~ scanf ("%d%d%d" , &row , &col , &o)) {
if (row == && col == && o == )
break ;
memset (a , , sizeof(a)) ;
for (int i = ; i <= row ; i++)
for (int j = ; j <= col ; j++)
cin >> map[i][j] ; solve () ;
/* for (int i = 1 ; i <= row ; i++) {
for (int j = 1 ; j <= col ; j++) {
printf ("%d " , a[i][j]) ;
}
puts ("") ;
}
printf ("\n\n") ;*/
}
return ;
}
Robot Motion(imitate)的更多相关文章
- poj1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12507 Accepted: 6070 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) ...
随机推荐
- 从Lumia退役看为什么WP走向没落
前段时间决定将自己用了三年多的Lumia 800正式退役,这是我用的时间最长的手机,虽然系统上有缺陷,但是好不妨碍他成为我最有感情的一部手机.由于之前是WinPhone 开发者的关系,这部手机是微软送 ...
- css3动画 bug 2点
1. .myanimate{ transition-property: left;transition-duration: .3s;transition-timing-function: ease } ...
- cocos2d-x 3.0以上版本字体设置问题
cocos2d-x中的万年大坑,字体总算是有比较好的结局办法了.之前都是CCLabelTTF,CCLabelBMFont,CCLabelAtlas什么的,我只想说一句:好难用!毕竟是做游戏,那么难看的 ...
- NuGet更新引用Dll
第一种 通过 "Add Library Package Reference..." 添加 点击 ‘Add Library Package Reference...’ , 搜索你要添 ...
- WCF入门(9)
前言 上次搬家空调出了点问题,和修空调的师傅商量了一下,感觉还是讲理的. 今天又在公司基本没有任何存在感的过了一天,纠结...领导还不在... 前些天往手机里面放了几集WCF入门视频,今天用暴风影音看 ...
- SQL删除重复的记录(只保留一条)
首先新建表: --创建示例表 CREATE TABLE t ( id ,) PRIMARY KEY, a ), b ) ) --插入数据 INSERT INTO t SELECT 'aa','bb' ...
- javascript 漏洞
1.javascript语言中,每一个对象都有一个对应的原型对象,称为prototype对象. 继承是基于原型的! 2.prototype对象的作用,就是定义所有实例对象共享的属性和方法! 3.“原 ...
- JS实现Ajax---例:获取服务器时间
Ajax在本质上是一个浏览器端的技术 XMLHttpRequest XMLHttpRequest对象 XMLHttpRequest对象在IE浏览器和非IE浏览器中创建的方法不同. 简而言之:它可以异步 ...
- sql-and、or
WHERE 指令可以被用来由表格中有条件地选取资料. 这个条件可能是简单的 (像上一页的例子),也可能是复杂的.复杂条件是由二或多个简单条件透过 AND 或是 OR 的连接而成.一个 SQL 语句中可 ...
- 详解HTML中的window对象和document对象
Window -- 代表浏览器中一个打开的窗口: 对象属性 window //窗口自身 window.self //引用本窗户window=window.self window.name //为窗口命 ...