POJ-1573 Robot Motion模拟
题目链接:
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模拟的更多相关文章
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
- POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- POJ 1573 Robot Motion(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- poj 1573 Robot Motion_模拟
又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- [ACM] hdu 1035 Robot Motion (模拟或DFS)
Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...
- PKU 1573 Robot Motion(简单模拟)
原题大意:原题链接 给出一个矩阵(矩阵中的元素均为方向英文字母),和人的初始位置,问是否能根据这些英文字母走出矩阵.(因为有可能形成环而走不出去) 此题虽然属于水题,但是完全独立完成而且直接1A还是很 ...
随机推荐
- 剑指Offer-求1+2+3+...+n
package Other; /** * 求1+2+3+...+n * 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句( ...
- Learn Plan
2018-02-05 1.正则表达式的熟悉和使用 2.Spring-boot 框架的使用 3.React的如何和使用 4.英语的单词发音的纠正和词汇的记忆. 5.github 命令行的使用 6.jav ...
- SpringMvc的传递参数方式 -- url / requestMapping
在使用spring的项目中,前台传递参数到后台是经常遇到的事, 我们必须熟练掌握一些常用的参数传递方式和注解的使用,废话少说,直接上正文. 1. @requestMapping: 类级别和方法级别的注 ...
- 使用git将本地代码传到github
方法可能有些小小的差别,但是最终的结果都是一样的 在github上新建代码仓库 确定之后会显示一个仓库的url,复制下来 在本地找一个作为本地仓库的文件夹右键Git Bash Here打开git 把g ...
- Java面向对象特性--多态
Java是一种面向对象的编程语言,面向对象的三大特性就是继承,封装,多态.下面细细说一说多态. 多态的定义:一个事物的多种形态,指允许不同类的对象对同一消息做出响应.即同一消息可以根据发送对象的不同而 ...
- poj-1146 ID codes
Description It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In or ...
- iOS CocoaPods一些特别的用法 指定版本、版本介绍、忽略警告
简介 介绍一些CocoaPods一些特别的用法 CocoaPods github地址 CocoaPods 官方地址 1. 指定第三方库版本 1. 固定版本 target 'MyApp' do use_ ...
- c++ --> const关键字总结
const关键字总结 C++中的const关键字的用法非常灵活,而使用const将大大改善程序的健壮性.const 是C++中常用的类型修饰符,常类型是指使用类型修饰符const说明的类型,常类型的变 ...
- 关于HTML使用ComDlg ActiveX 无法弹出相应对话框的问题1
最近发现,开发的Web应用在客户的某些IE(8,9,11)中弹出不了Windows的字体对话框. 通过 F12 跟踪,错误代码是“-2146827850”,错误信息是“ 对象不支持ShowFont属性 ...
- git项目初始化
Command line instructions 1.Git global setup git config --global user.name "99176942"git c ...