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 ...
随机推荐
- python入门(七):CGI编程
CGI CGI(Common Gateway Interface),通用网关接口,HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上. CGI在其中扮演的是在we ...
- 学习《深入理解C#》—— 数据类型、排序和过滤 (第一章1.1---1.2)
引言 在开始看这本书之前看过一些技术博客,填补自己对于一些知识点的不足.无意中发现了<深入理解C#>这本书,本书主要探讨C# 2.C# 3和C# 4的细节与特性,所以做了一下阅读笔记,欢迎 ...
- iOS开发经验总结(一)
本文转载至 :http://dreamahui.iteye.com/blog/1878650 软件开发方面 1. 在每个页面的入口和出口(一般是viewDidLoad和dealloc)打上日志,可以 ...
- Surface UEFI 菜单显示
下载 Surface 的恢复映像 https://support.microsoft.com/zh-cn/surfacerecoveryimage UEFI 设置只能在系统启动时进行调整.若要加载 ...
- Javascript中的window.event.keyCode使用介绍
<body onkeydown=" alert(window.event.keyCode)"> <body onkeydown="if(window.e ...
- 1853: [Scoi2010]幸运数字[容斥原理]
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2405 Solved: 887[Submit][Status] ...
- chkcofnig-minimal-script
author :headsen chen date: 2018-06-04 12:02:27 #!/bin/bash for i in `chkconfig --list |awk '{print ...
- 【BZOJ2525】[Poi2011]Dynamite 二分+树形DP
[BZOJ2525][Poi2011]Dynamite Description Byteotian Cave的结构是一棵N个节点的树,其中某些点上面已经安置了炸.药,现在需要点燃M个点上的引线引爆所有 ...
- Maven开发系统
Maven的优点: 自动从互联网中获取jar包,并实现了一步构建. pom.xml的配置 依赖管理(导入对应的jar包) 通过坐标(定位到仓库中的包的位置,并将jar包导入到项目中,如果版本升级,只需 ...
- Zabbix添加web页面监控告警
一,选择添加了web监控的主机 二,创建一个告警触发器 三,定义监控项 设置完毕假如网站down就会触发告警 怎么设置web监控以及触发告警action参考 Zabbix使用SMTP发送邮件报警并且制 ...