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) ...
随机推荐
- 【MPI学习7】MPI并行程序设计模式:MPI的进程组和通信域
基于都志辉老师MPI编程书中的第15章内容. 通信域是MPI的重要概念:MPI的通信在通信域的控制和维护下进行 → 所有MPI通信任务都直接或间接用到通信域这一参数 → 对通信域的重组和划分可以方便实 ...
- 图片ping、JSONP和CORS跨域
置顶文章:<纯CSS打造银色MacBook Air(完整版)> 上一篇:<由外边距合并到BFC> 作者主页:myvin 博主QQ:851399101(点击QQ和博主发起临时会话 ...
- Android Studio配置Git及Git文件状态说明
Android Studio配置Git还是比较简单的,麻烦的是可能中间出现各种问题.如果你想了解或感兴趣,请往下看. 首先你得下载Git客户端,网址:http://git-scm.com/downlo ...
- WPF开发时光之痕日记本——终于完工了。。晒晒截图(三)(已上传安装包)
由于是业余时间学习的 WPF 的相关开发且不怎么会使用 Blend 软件,所以开发这个客户端着实花费了我很长时间,比如文本编辑器的开发,最初是在 Simple.HtmlEditor 的基础上做的修改, ...
- Git.Framework 框架随手记--准备工作
前面已经提到过了本框架的由来,时至今日该框架已经和最初版本有了天壤之别.因为仍有部分代码是采用原有的框架,所以本框架也算不上原创,只是在原有的基础上不断的改进,所以希望了解此框架的人不要过多的指责. ...
- CSS3——3D效果
1.效果1 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" c ...
- NumberFormat类的用法
NumberFormat.getInstance()方法返回NumberFormat的一个实例(实际上是NumberFormat具体的一个子类,例如DecimalFormat), 这适合根据本地设置格 ...
- WCF调用时提示错误 "已尝试创建到达不支持 .Net 框架的服务的通道。可能遇到 HTTP 终结点"
一个以前运行的很正常的项目,某天突然无法连接WCF构建的后台.使用WCFTestClient连接到服务是正常的,但是调用服务中的方式时就报出了以下错误: 已尝试创建到达不支持 .Net 框架的服务的通 ...
- linux更改文件所有者命令chown命令的使用困惑
[berry@berry:practice] ls -lrt total -rwxrwxrwx berry berry Dec : f1.txt -rwxrwxrwx berry berry Dec ...
- 【bzoj3150】 cqoi2013—新Nim游戏
www.lydsy.com/JudgeOnline/problem.php?id=3105 (题目链接) 题意 在第一个回合中,第一个游戏者可以直接拿走若干个整堆的火柴.可以一堆都不拿,但不可以全部拿 ...