PKU 1573 Robot Motion(简单模拟)
原题大意:原题链接
给出一个矩阵(矩阵中的元素均为方向英文字母),和人的初始位置,问是否能根据这些英文字母走出矩阵.(因为有可能形成环而走不出去)
此题虽然属于水题,但是完全独立完成而且直接1A还是很开心的
注意:对于形成环的情况则从进入环的交点处重新走一遍,记录步数即可
#include<cstdio>
#include<cstring>
int n,m,p;
bool vis[][];
char str[][];
bool can(int x,int y)
{
if(x<||x>n||y<||y>m||vis[x][y])
return false;
return true;
}
int main()
{
while(scanf("%d%d%d",&n,&m,&p),n|m|p){
memset(vis,,sizeof(vis));
getchar();
for(int i=;i<=n;i++){
for(int j=;j<=m;j++)
scanf("%c",&str[i][j]);
getchar();
}
int x=,y=p,step1=;
while(can(x,y)){
int px=x,py=y;
vis[px][py]=;
if(str[px][py]=='E')
{y++,step1++;}
else if(str[px][py]=='S')
{x++,step1++;}
else if(str[px][py]=='W')
{y--,step1++;}
else if(str[x][y]=='N')
{x--,step1++;}
}
if(vis[x][y]){
int step2=,ox=x,oy=y;
while(){
int px=x,py=y;
if(str[px][py]=='E')
{y++,step2++;}
else if(str[px][py]=='S')
{x++,step2++;}
else if(str[px][py]=='W')
{y--,step2++;}
else if(str[px][py]=='N')
{x--,step2++;}
if(x==ox&&y==oy){
printf("%d step(s) before a loop of %d step(s)\n",step1-step2,step2);
break;
}
}
}
else printf("%d step(s) to exit\n",step1);
}
}
PKU 1573 Robot Motion(简单模拟)的更多相关文章
- POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- POJ1573(Robot Motion)--简单模拟+简单dfs
题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...
- 模拟 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 ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- poj1573&&hdu1035 Robot Motion(模拟)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接: HDU:pid=1035">http://acm.hd ...
随机推荐
- 蓝桥杯 历届试题 剪格子(dfs搜索)
历届试题 剪格子 时间限制:1.0s 内存限制:256.0MB 问题描述 如下图所示,3 x 3 的格子中填写了一些整数. +--*--+--+ |* || +--****--+ ||* | ** ...
- 对Python线程池
本文对Python线程池进行详细说明介绍,IDE选择及编码的解决方案进行了一番详细的描述,实为Python初学者必读的Python学习经验心得. AD: 干货来了,不要等!WOT2015 北京站演讲P ...
- Hive将txt、csv等文本文件导入hive表
1.将txt文本文件放置hdfs目录下 2.登录hive并进入到指定数据库 3.创建表 create external table if not exists fun_user_external ( ...
- Linux命令之乐--time
time用于统计命令执行花费的总时间 例一: [root@Director usr]# time ls bin etc games include java lib lib64 libexec loc ...
- Tiny4412 Android 5.0 编译系统学习笔记
1.Android 编译系统概述 Build 系统中最主要的处理逻辑都在 Make 文件中,而其他的脚本文件只是起到一些辅助作用. 整个 Build 系统中的 Make 文件可以分为三类: ① Bui ...
- webpack 报错 path is not defind
webpack.config.js里的内容是这样的,注意标红的地方: 首先,绝对路径'./dist'是 没有问题的 那么,查了很多,最后看到别人的webpack.config.js里面这样写着,现在c ...
- 快速解决:windows安装程序无法将windows配置为在此计算机的硬件上运行
用手工运行msoobe.ext启用配置的方法, 快速解决:windows安装程序无法将windows配置为在此计算机的硬件上运行 我自己安装碰到的是蓝色这个错误,下面这个也有网友说用安装驱动等方法 ...
- C 语言开发初涉-01 简单学习
尝试用C语言写windows程序: 简单的计算器 1.0版,仅用来熟悉C 开发windows的一些语法和语句用法 #include "stdafx.h" #include < ...
- 170413、怎么精确理解leader布置的任务(技术外的话)
[缘起] 和一个同学交代了一个很重要的事情,结果执行的结果并不是自己想要的,微微生气之余,简单的聊聊“如何精确的理解leader布置的任务”. [员工角度的潜在困惑] 1)leader讲了很多,脑子记 ...
- 160606、springmvc中使用Spring Mobile
springmobile特点: 1.客户端设备识别:识别结果只有3种类型:NORMAL(非手机设备).MOBILE(手机设备).TABLET(平板电脑). 2.网站偏好设置:Spring 通过设备识别 ...