题目链接:

https://vjudge.net/problem/POJ-1573

题目大意:

有一个N*M的区域,机器人从第一行的第几列进入,该区域全部由'N' , 'S' , 'W' , 'E' ,走到某个区域的时候只能按照该区域指定的方向进行下一步,问你机器人能否走出该片区域,若不能,输入开始绕圈的步数和圈的大小。

思路:

一开始一直WA,后来发现是因为vis数组的问题,这里设置的vis数组表示到该点走的步数,最开始是0步,这和初始化是0步是一样的,会导致如果再次走到这个点,就会判断成该点没有走过,后来初始化成-1,A了

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + ;
const int INF = << ;
int dir[][] = {,,,,-,,,-};
int T, n, m, x;
map<char, int>M;
int Map[][];
int vis[][];
void dfs(int x, int y, int d)
{
//cout<<x<<" "<<y<<" "<<d<<endl;
if(x <= || x > n || y <= || y > m)
{
cout<<d<<" step(s) to exit"<<endl;
return;
}
if(vis[x][y] != -)
{
cout<<vis[x][y]<<" step(s) before a loop of "<<d - vis[x][y]<<" step(s)"<<endl;
return;
}
int cn = Map[x][y];
vis[x][y] = d;
dfs(x + dir[cn][], y + dir[cn][], d + );
}
int main()
{
M['S'] = ;
M['E'] = ;
M['N'] = ;
M['W'] = ; while(cin >> n >> m >> x)
{
if(!n && !m && !x)break;
memset(vis, -, sizeof(vis));
//这里不能设置成0,应该设置成-1,因为设置成0的话,第一步出发设置的也是0,这样就会把第一步标记成未走过的点了
memset(Map, , sizeof(Map));
char c;
for(int i = ; i <= n; i++)
{
for(int j = ;j <= m; j++)
{
cin >> c;
Map[i][j] = M[c];
}
}
dfs(, x, );
}
return ;
}

POJ-1573 Robot Motion模拟的更多相关文章

  1. POJ 1573 Robot Motion 模拟 难度:0

    #define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...

  2. 模拟 POJ 1573 Robot Motion

    题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...

  3. POJ 1573 Robot Motion(模拟)

    题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...

  4. poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】

                                                                                                         ...

  5. POJ 1573 Robot Motion(BFS)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12856   Accepted: 6240 Des ...

  6. POJ 1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12978   Accepted: 6290 Des ...

  7. poj 1573 Robot Motion_模拟

    又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...

  8. Poj OpenJudge 百练 1573 Robot Motion

    1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...

  9. [ACM] hdu 1035 Robot Motion (模拟或DFS)

    Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...

  10. PKU 1573 Robot Motion(简单模拟)

    原题大意:原题链接 给出一个矩阵(矩阵中的元素均为方向英文字母),和人的初始位置,问是否能根据这些英文字母走出矩阵.(因为有可能形成环而走不出去) 此题虽然属于水题,但是完全独立完成而且直接1A还是很 ...

随机推荐

  1. Spring Boot 定时任务的使用

    @Configuration @EnableScheduling public class ScheduleConfig { private final Logger logger = LoggerF ...

  2. CXF对Interceptor拦截器的支持

    前面在Axis中介绍过Axis的Handler,这里CXF的Interceptor就和Handler的功能类似.在每个请求响应之前或响应之后,做一些事情.这里的Interceptor就和Filter. ...

  3. dom4j 最常用最简单的用法(转)

    要使用dom4j读写XML文档,需要先下载dom4j包,dom4j官方网站在 http://www.dom4j.org/目前最新dom4j包下载地址:http://nchc.dl.sourceforg ...

  4. Python开发简单爬虫(二)---爬取百度百科页面数据

    一.开发爬虫的步骤 1.确定目标抓取策略: 打开目标页面,通过右键审查元素确定网页的url格式.数据格式.和网页编码形式. ①先看url的格式, F12观察一下链接的形式;② 再看目标文本信息的标签格 ...

  5. Java基础学习笔记二十四 MySQL安装图解

    .MYSQL的安装 1.打开下载的mysql安装文件mysql-5.5.27-win32.zip,双击解压缩,运行“setup.exe”. 2.选择安装类型,有“Typical(默认)”.“Compl ...

  6. Property 'id' not found on type java.lang.String

    改为 忘写了$符,取不出来,因此报错!

  7. 用 Go 编写一个简单的 WebSocket 推送服务

    用 Go 编写一个简单的 WebSocket 推送服务 本文中代码可以在 github.com/alfred-zhong/wserver 获取. 背景 最近拿到需求要在网页上展示报警信息.以往报警信息 ...

  8. 20162328蔡文琛week07

    学号 2016-2017-2 <程序设计与数据结构>第X周学习总结 教材学习内容总结 多态引用在不同的时候可以指向不同类型的对象. 多态引用在运行时才将方法调用用于它的定义绑定在一起. 引 ...

  9. SciPy - 科学计算库(上)

    SciPy - 科学计算库(上) 一.实验说明 SciPy 库建立在 Numpy 库之上,提供了大量科学算法,主要包括这些主题: 特殊函数 (scipy.special) 积分 (scipy.inte ...

  10. scrapy crawl rules设置

    rules = [ Rule(SgmlLinkExtractor(allow=('/u012150179/article/details'), restrict_xpaths=('//li[@clas ...