HDU1035 Robot Motion

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 <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h> using namespace std; int key[][]; int main()
{
int a,b,p;
while(scanf("%d%d",&a,&b)&&a&&b)
{
scanf("%d",&p);
char arr[a][b];
int i,j;
for(i=;i<a;i++)
scanf("%s",&arr[i]); int s=,flag=;
i=;
j=p-;
while(true)
{
if(arr[i][j]=='N')
{
key[i][j]=s;
arr[i][j]='A';
i--;
} else if(arr[i][j]=='S')
{
key[i][j]=s;
arr[i][j]='A';
i++;
}
else if(arr[i][j]=='W')
{
key[i][j]=s;
arr[i][j]='A';
j--;
}
else if(arr[i][j]=='E')
{
key[i][j]=s;
arr[i][j]='A';
j++;
}
s++; if(arr[i][j]=='A')
{
flag=;
break;
}
if(i<||i==a||j<||j==b)
break;
}
if(flag)
printf("%d step(s) before a loop of %d step(s)\n",key[i][j],s-key[i][j]);
else
printf("%d step(s) to exit\n",s);
}
return ;
}
HDU1035 Robot Motion的更多相关文章
- HDU-1035 Robot Motion
http://acm.hdu.edu.cn/showproblem.php?pid=1035 Robot Motion Time Limit: 2000/1000 MS (Java/Others) ...
- hdu1035 Robot Motion (DFS)
Robot Motion Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- poj1573&&hdu1035 Robot Motion(模拟)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接: HDU:pid=1035">http://acm.hd ...
- HDU-1035 Robot Motion 模拟问题(水题)
题目链接:https://cn.vjudge.net/problem/HDU-1035 水题 代码 #include <cstdio> #include <map> int h ...
- 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 ...
随机推荐
- linux系统中的删除操作
#rm [-fir] 文件或者目录 参数: -f:就是force的意思,忽略不存在的文件,不会出现警告信息: -i:互动模式,在删除前会询问用户是否操作: -r:递归删除.最常用的在目录删除.这是一个 ...
- scala环境配置+hello world!
下载地址: http://www.scala-lang.org/download/ 我下载的是zip 配置环境变量 需要jdk支持,jdk的安装配置此处略过 控制台命令 scala -version ...
- 通过 pxe(网络安装)完成centos 系统的网络安装
首先交代环境.本地2台主机,一台windows主机,一台等待安装centos的主机.2台主机在同一个局域网.通过路由器自动获取ip上网. 网上大多数pxe安装方式都采用自己搭建dns服务器的方式来进行 ...
- Hadoop 笔记1 (原理和HDFS分布式搭建)
1. hadoop 是什么 以及解决的问题 (自行百度) 2.基本概念的讲解 1. NodeName master 节点(NN) 主节点 保存了metaData(元数据信息) 包括文件的owener ...
- Linux: 安装NVIDIA显卡驱动
Linux(Fedora25, 64bit)台式机配备了NVIDIA显卡GTX950,但是仅仅使用开源驱动nouveau,无法发挥NVIDIA显卡的性能,所以可以考虑使用官方提供的显卡驱动. # 先安 ...
- Kafka 源代码分析之Log
这里分析Log对象本身的源代码. Log类是一个topic分区的基础类.一个topic分区的所有基本管理动作.都在这个对象里完成.类源代码文件为Log.scala.在源代码log目录下. Log类是L ...
- 框架基础:ajax设计方案(五)--- 集成promise规范,更优雅的书写代码
距离上一篇博客书写,又过去了大概几个月了,这段时间暂时离开了这个行业,让大脑休息一下.一个人旅行,一个人休息,正好也去完成一个目标 --- 拥有自己的驾照.当然,也把自己晒的黑漆马虎的.不过这一段时间 ...
- 把sql输出成。sql文件
作者原创,转载注明出处: 代码: package importfile; import java.io.*; import java.io.PrintWriter; import java.sql.C ...
- ArchSummit全球架构师峰会2017年深圳站 漫谈
自去年6月跳槽到某CDN厂,从偏向移动端开发又回到了专注后端,关于做一个移动应用独立开发者的计划暂时搁置,但是如马云所讲: "梦想还是要有的,万一实现了呢".去年下半年辛苦加班加点 ...
- ActiveMQ 503错误
问题描述: 在Linux系统下安装ActiveMQ,启动服务 正常启动后,通过浏览器进行访问 可以正常显示home页面,但是点击其他菜单,如Queues,Topics等,都会出现503错误,如图 问题 ...