Robot Motion

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5011    Accepted Submission(s): 2321

Problem 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
There will be one or more grids for robots to navigate. The data for each is in the following form. On the first line are three integers separated by blanks: the number of rows in the grid, the number of columns in the grid, and the number of the column in which the robot enters from the north. The possible entry columns are numbered starting with one at the left. Then come the rows of the direction instructions. Each grid will have at least one and at most 10 rows and columns of instructions. The lines of instructions contain only the characters N, S, E, or W with no blanks. The end of input is indicated by a row containing 0 0 0.
 
Output
For each grid in the input there is one line of output. Either the robot follows a certain number of instructions and exits the grid on any one the four sides or else the robot follows the instructions on a certain number of locations once, and then the instructions on some number of locations repeatedly. The sample input below corresponds to the two grids above and illustrates the two forms of output. The word "step" is always immediately followed by "(s)" whether or not the number before it is 1.
 
Sample Input
3 6 5
NEESWE
WWWESS
SNWWWW
4 5 1
SESWE
EESNW
NWEEN
EWSEN
0 0
 
Sample Output
10 step(s) to exit
3 step(s) before a loop of 8 step(s)
 
Source
 模拟题..
 #include<cstdio>
#include<cstring>
const int maxn=;
char maze[][maxn];
int record[][maxn];
int main()
{
int r,c,pos,i,j;
while(scanf("%d%d",&r,&c),r+c)
{
scanf("%d",&pos);
memset(maze,'\0',sizeof maze);
memset(record,,sizeof record);
for( i=;i<r;i++)
{
scanf("%s",maze[i]);
}
int newr=,newc=pos-;
bool judge=true;
while(newc>=&&newr>=&&maze[newr][newc]!=)
{
record[newr][newc]++;
if(record[newr][newc]==)
{
judge=false;
break;
} switch(maze[newr][newc])
{
case 'N': newr--; break; //up
case 'S': newr++; break; //down
case 'E': newc++; break; //right
case 'W': newc--; break; //left }
}
int step=,circle=;
for( i=;i<r;i++)
{
for( j=;j<c;j++)
{
if(record[i][j]==)
step++;
else
if(record[i][j]!=)
circle++; }
} if(judge)
printf("%d step(s) to exit\n",step);
else
printf("%d step(s) before a loop of %d step(s)\n",step,circle);
}
return ;
}

HDUOJ-----Robot Motion的更多相关文章

  1. poj1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12507   Accepted: 6070 Des ...

  2. Robot Motion(imitate)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11065   Accepted: 5378 Des ...

  3. 模拟 POJ 1573 Robot Motion

    题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...

  4. POJ 1573 Robot Motion(BFS)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12856   Accepted: 6240 Des ...

  5. Robot Motion 分类: POJ 2015-06-29 13:45 11人阅读 评论(0) 收藏

    Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11262 Accepted: 5482 Descrip ...

  6. POJ 1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12978   Accepted: 6290 Des ...

  7. Poj OpenJudge 百练 1573 Robot Motion

    1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...

  8. POJ1573——Robot Motion

    Robot Motion Description A robot has been programmed to follow the instructions in its path. Instruc ...

  9. hdoj 1035 Robot Motion

    Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  10. HDU-1035 Robot Motion

    http://acm.hdu.edu.cn/showproblem.php?pid=1035 Robot Motion Time Limit: 2000/1000 MS (Java/Others)   ...

随机推荐

  1. ListPopupWindow 列表弹窗 常见弹窗区别

    案例 private void showPopupWindow(final Context context, @NonNull View anchorView) { final String[] po ...

  2. Java面试问题总结

    前几天Java面试中遇到的问题,这仅仅是当中的一部分问题.面试中有非常多问题是关于数据结构和算法的.在这里做下总结,希望有能力的人能够试着做一下,并在评论区留下您的答案.让大家相互学习.谢谢 程序设计 ...

  3. Java复习2-对象与类

    回顾基础知识过程中遇到的感觉需要记录一下的知识点. 封装 我们设计的class应当尽可能的高内聚,体现为封装的程度.一个class的属性应该只能自己修改,其他class都只是与本class沟通,而不应 ...

  4. 怎样将 MySQL 迁移到 MariaDB 上

    自从甲骨文收购 MySQL 后,由于甲骨文对 MySQL 的开发和维护更多倾向于闭门的立场,很多 MySQL 的开发者和用户放弃了它.在社区驱动下,促使更多人移到 MySQL 的另一个叫 MariaD ...

  5. OCR 基本知识

    OCR,optical character recognition 的简称,也就是光学识别系统,属于图形识别的一个分支,OCR是针对印刷体字符,採用光学的方式将文档资料转换成原始资料黑白点阵的图像文件 ...

  6. Setting a maximum attachment size

      By default IBM® Lotus® iNotes™ allows a maximum attachment size of 50,000K (50MB). You can increas ...

  7. 前端html用一个表单来映射后台多个对象

    public class entity1 { private String id; public String getId() { return id; } public void setId(Str ...

  8. 【Python】torrentParser1.00

    代码: #------------------------------------------------------------------------------------ # torrentP ...

  9. register_shutdown_function函数详解--脚本退出时执行回调函数

    register_shutdown_function — Register a function for execution on shutdown. ps:Registers a callback  ...

  10. 微软BI 之SSRS 系列 - 使用分组 Group 属性实现基于父子递归关系的汇总报表

    基于父子关系的递归结构在公司组织结构里比较常见,基本上都是在一张表里实现的自引用关系.在报表中如果要实现这种效果,并且在这个基础上做一些数据的汇总,可以使用到下面提到的方法. 要实现的效果大致如下 - ...