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(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
随机推荐
- HDU--2040
亲和数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- [转] Linux TCP/IP网络小课堂:net-tools与iproute2大比较
PS:netstat选项是-planet,方便记忆 http://os.51cto.com/art/201409/450886.htm 如今许多系统管理员仍结合使用ifconfig.route.arp ...
- Java基础知识强化之集合框架笔记04:Collection集合的基本功能测试
1. Collection集合的基本功能测试: package cn.itcast_01; import java.util.ArrayList; import java.util.Collectio ...
- SPOJ 4053 - Card Sorting 最长不下降子序列
我们的男主现在手中有n*c张牌,其中有c(<=4)种颜色,每种颜色有n(<=100)张,现在他要排序,首先把相同的颜色的牌放在一起,颜色相同的按照序号从小到大排序.现在他想要让牌的移动次数 ...
- codevs 2541 幂运算(迭代加深搜索)
/* 一开始想到了简单的深搜 维护当前可用的mi数组 然后回溯用哪个 不断更新新产生的mi 这样的问题是 由于mi不断产生 搜索规模扩大 不好 不好 下面是奇丑的WA掉的代码 做个反面教材 */ #i ...
- input输入过滤js
html部分使用方式 <input onkeyup="usrNameSet(this)" /> 其它的自己可以随便调用 Js部分 //只能输入数字.字母.小数点.汉字 ...
- Html5 Canvas Text
html5 canvas中支持对text文本进行渲染;直接的理解就是把text绘制在画布上,并像图形一样处理它(可以加shadow.gradient.pattern.color fill等等):既然它 ...
- jquery 的缺点
接口不统一 其中.each();.map();$.each();这些方法的参数函数的参数顺序是index, value这种顺序.但是$.map();方法的参数函数的参数顺序则是value,index这 ...
- mssql sql高效关联子查询的update 批量更新
/* 使用带关联子查询的Update更新 --1.创建测试表 create TABLE Table1 ( a varchar(10), b varchar(10), ...
- 关于NSURL的一些属性的记录
关于NSURL的一些属性的记录 NSLog(@"%@", request.URL.absoluteString); NSLog(@"%@", request.U ...