HDUOJ-----Robot Motion
Robot Motion
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5011 Accepted Submission(s): 2321
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.
#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的更多相关文章
- poj1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12507 Accepted: 6070 Des ...
- Robot Motion(imitate)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11065 Accepted: 5378 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) ...
随机推荐
- ListPopupWindow 列表弹窗 常见弹窗区别
案例 private void showPopupWindow(final Context context, @NonNull View anchorView) { final String[] po ...
- Java面试问题总结
前几天Java面试中遇到的问题,这仅仅是当中的一部分问题.面试中有非常多问题是关于数据结构和算法的.在这里做下总结,希望有能力的人能够试着做一下,并在评论区留下您的答案.让大家相互学习.谢谢 程序设计 ...
- Java复习2-对象与类
回顾基础知识过程中遇到的感觉需要记录一下的知识点. 封装 我们设计的class应当尽可能的高内聚,体现为封装的程度.一个class的属性应该只能自己修改,其他class都只是与本class沟通,而不应 ...
- 怎样将 MySQL 迁移到 MariaDB 上
自从甲骨文收购 MySQL 后,由于甲骨文对 MySQL 的开发和维护更多倾向于闭门的立场,很多 MySQL 的开发者和用户放弃了它.在社区驱动下,促使更多人移到 MySQL 的另一个叫 MariaD ...
- OCR 基本知识
OCR,optical character recognition 的简称,也就是光学识别系统,属于图形识别的一个分支,OCR是针对印刷体字符,採用光学的方式将文档资料转换成原始资料黑白点阵的图像文件 ...
- Setting a maximum attachment size
By default IBM® Lotus® iNotes™ allows a maximum attachment size of 50,000K (50MB). You can increas ...
- 前端html用一个表单来映射后台多个对象
public class entity1 { private String id; public String getId() { return id; } public void setId(Str ...
- 【Python】torrentParser1.00
代码: #------------------------------------------------------------------------------------ # torrentP ...
- register_shutdown_function函数详解--脚本退出时执行回调函数
register_shutdown_function — Register a function for execution on shutdown. ps:Registers a callback ...
- 微软BI 之SSRS 系列 - 使用分组 Group 属性实现基于父子递归关系的汇总报表
基于父子关系的递归结构在公司组织结构里比较常见,基本上都是在一张表里实现的自引用关系.在报表中如果要实现这种效果,并且在这个基础上做一些数据的汇总,可以使用到下面提到的方法. 要实现的效果大致如下 - ...