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 ...
随机推荐
- (转)c指针问题
字符串常量问题: http://blog.csdn.net/zhongyili_sohu/article/details/8084188 1. 常量字符串 在代码里直接出现的”abcdef”这种字符串 ...
- 有用的Python代码片段
我列出的这些有用的Python代码片段,为我节省了大量的时间,并且我希望他们也能为你节省一些时间.大多数的这些片段出自寻找解决方案,查找博客和StackOverflow解决类似问题的答案.下面所有的代 ...
- hdu 1813(IDA*)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1813 思路:首先bfs预处理出‘0’到边界点最短距离,然后构造 h() 为所’0‘点逃离迷宫的最少步数 ...
- iOS开发中多线程基础
耗时操作演练 代码演练 编写耗时方法 - (void)longOperation { for (int i = 0; i < 10000; ++i) { NSLog(@"%@ %d&q ...
- Linux命令之乐--cat
cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 命令参数: -A, --show-all ...
- [UIImage _isCached]: message sent to deallocated instance
本文转载至 http://zhuhaibobb.blog.163.com/blog/static/2744006720124191633375/ 这几天做了个APP打开20份钟左右就强制退 ...
- JSP内置对象——application,page,pageContext,config,Exception
application对象application对象实现了用户数据的共享,可存放全局变量.application开始于服务器的启动,终止于服务器的关闭.在用户的前后链接或不同用户之间的连接中,可以对a ...
- win10怎么关闭把管理员权限
按住WIN+R 计算机配置----Windows设置----安全设置----本地策略----安全选项----用户账户控制:以管理员批准模式运行所有管理员,把启用改为禁止然后重启电脑
- Codeforces Round #190 (Div. 2).D
一道贪心题. 可以分两种情况 1 .是没有把对面的牌全打败,那么只要用最大的可能去打攻击状态的牌. 2. 是将对面的牌全打败,那么只要保证打对面防守状态的花费最小,就可以保证最后的结果最大 两种情况下 ...
- Fragment、FragmentTabHost以及RadioGroup框架
package com.dotfive.chuanbang.activity; import test.Fragment1; import test.Fragment1.OnBackListener; ...