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) ...
随机推荐
- Java方法containsAll学习
有时候我们需要判断B链表是不是A链表的子集,我们可以使用A.containsAll(B)来判断,当返回值是true的时候就表明B链表是A链表的子集,当返回值是false时候就表明B链表不是A链表的子集 ...
- MFC中查找替换对话框CFindReplaceDialog类
void CCFindReplaceDialogView::OnFind() { CFindReplaceDialog* pDlg = new CFindReplaceDialog(); pDlg-& ...
- 【站长起步】阿里云+Ubuntu+java 7+ Tomcat 7 +Nginx1.6 +Mysql 5.6
本文记载了在阿里云ubuntu+java 镜像环境下搭建站点server环境中遇到的的错误和解决方式. 作为一个年轻人,是肯定不会去用alidata这个现成的环境的.怎么办? 所有删除.立刻创建一个 ...
- 阿里巴巴Java开发规约插件全球首发!(转)
https://mp.weixin.qq.com/s?__biz=MzI0NTE4NjA0OQ==&mid=2658355901&idx=1&sn=3169172bfc6819 ...
- 上机题目(0基础)- Java网络操作-打印网页(Java)
打印一个网页,熟悉Java网络编程: import java.io.BufferedReader; import java.io.IOException; import java.io.InputSt ...
- 一次jdbc乱码解决
今天我做了一个小实验,从sqlserver 2010中将一张表转移到mysql中,使用的是基本的jdbc,前面复制的好好地,不知道怎么了,到了第三万行,突然出现了下面的异常 Incorrect str ...
- Direct2D教程III——几何(Geometry)对象
目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...
- 20160205.CCPP体系具体解释(0015天)
程序片段(01):01.杨辉三角.c 内容概要:杨辉三角 #include <stdio.h> #include <stdlib.h> #define N 10 //01.杨辉 ...
- javascript高级语法学习
可维护的代码意味着: 可读的 一致的 可预测的 看上去就像是同一个人写的 已记录 命名函数表达式 (function fn(){}) 他是表达式的原因是因为括号 ()是一个分组操作符,它的内部只能包含 ...
- WinForm 之 VS2010发布、打包安装程序
第一步.在vs2010 打开要打包的应用程序解决方案,右键“ 解决方案 ” → “ 添加 ” → “ 新建项目 ” → “ 其他项目类型 ” → “ 安装和部署 ” → “ Visual Studio ...