POJ1573 Robot Motion(模拟)
题目链接。
分析:
很简单的一道题,
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <queue> using namespace std; const int maxn = ; int dx[] = {-, , , };//上右下左
int dy[] = {, , , -}; char G[maxn][maxn];
int step[maxn][maxn];
bool vis[maxn][maxn];
int n, m, ex_step, lo_step; bool solve(int s) {
memset(vis, false, sizeof(vis));
step[][s-] = ;
vis[][s-] = true; int x = , y = s-, nx, ny; while(true) {
switch(G[x][y]) {
case 'N': nx = x + dx[]; ny = y + dy[]; break;
case 'E': nx = x + dx[]; ny = y + dy[]; break;
case 'S': nx = x + dx[]; ny = y + dy[]; break;
case 'W': nx = x + dx[]; ny = y + dy[]; break;
} if(nx < || nx >= n || ny < || ny >= m) {
ex_step = step[x][y];
return true;
} if(!vis[nx][ny]) { //exit
vis[nx][ny] = true;
step[nx][ny] = step[x][y] + ;
x = nx; y = ny;
}
else {//发现环
lo_step = step[x][y] + - step[nx][ny];
ex_step = step[nx][ny] - ;
return false;
}
}
} int main() {
int s; while(scanf("%d%d%d", &n, &m, &s) == ) {
if(n == && m == && s == ) break; for(int i=; i<n; i++) scanf("%s", G[i]); if(solve(s)) printf("%d step(s) to exit\n", ex_step);
else printf("%d step(s) before a loop of %d step(s)\n", ex_step, lo_step);
} return ;
}
POJ1573 Robot Motion(模拟)的更多相关文章
- POJ-1573 Robot Motion模拟
题目链接: https://vjudge.net/problem/POJ-1573 题目大意: 有一个N*M的区域,机器人从第一行的第几列进入,该区域全部由'N' , 'S' , 'W' , 'E' ...
- poj1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12507 Accepted: 6070 Des ...
- POJ1573——Robot Motion
Robot Motion Description A robot has been programmed to follow the instructions in its path. Instruc ...
- [ACM] hdu 1035 Robot Motion (模拟或DFS)
Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...
- POJ1573(Robot Motion)--简单模拟+简单dfs
题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...
- poj1573 Robot Motion(DFS)
题目链接 http://poj.org/problem?id=1573 题意 一个机器人在给定的迷宫中行走,在迷宫中的特定位置只能按照特定的方向行走,有两种情况:①机器人按照方向序列走出迷宫,这时输出 ...
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- HDU-1035 Robot Motion 模拟问题(水题)
题目链接:https://cn.vjudge.net/problem/HDU-1035 水题 代码 #include <cstdio> #include <map> int h ...
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
随机推荐
- Coppersmith-Winograd 算法
转自:https://www.douban.com/group/topic/29658298/ 对正整数 $q$,定义张量 $T$,其对应的多项式为 $p(X,Y,Z)=\sum_{i=1}^q (X ...
- ThinkPHP pdo连接Oracle的配置写法,提示报错
'DB_TYPE' => 'pdo', // 数据库类型 'DB_USER' => 'user101', // username 'DB_PWD' => 'zb~!@#$%', // ...
- LeetCode:Permutations(求全排列)
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- When does layoutSubviews get called?
转自:http://blog.logichigh.com/2011/03/16/when-does-layoutsubviews-get-called/ It’s important to optim ...
- YYModel 源码历险记 代码结构
前言 因为公司需要开发一个内部使用的字典转模型的项目,所以最近也是在看关于字典转模型的内容.有Mantle,jsonModel,MJExtension等众多框架,最后还是选择了先从YYModel源码读 ...
- Creating a Background Service ——IntentService
The IntentService class provides a straightforward structure for running an operation on a single ba ...
- poj 1780 code(欧拉路)
/* 对于n为密码想要序列最短 那么 1234 2345 这两个一定挨着 就是说 前一个的后n-1位是后一个的前n-1位 假设n==3 我们用0-99作为点的编号建图 然后每个点连出去10条边 两个相 ...
- codevs2059逃出克隆岛(传送门bfs)
/* 和普通的迷宫问题类似只是多了一个叫传送门的东西 对于传送门的处理: 每当跑到传送门就把其余所有传送门周围的点都入队 传送门之间不花费时间并且从不是传送门的点走到传送门 也不花费时间花费时间的(好 ...
- (多对象)Json转换成List
写的不好,请大家见谅. 1.Json 格式{"packages":[{“type”:”aaa”}],"zone_packages":[{"ticket ...
- C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化
转:http://www.cnblogs.com/lantionzy/archive/2009/10/23/1588511.html 1.新建Word文档 #region 新建Word文档/// &l ...