题目链接

分析:

很简单的一道题,

#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(模拟)的更多相关文章

  1. POJ-1573 Robot Motion模拟

    题目链接: https://vjudge.net/problem/POJ-1573 题目大意: 有一个N*M的区域,机器人从第一行的第几列进入,该区域全部由'N' , 'S' , 'W' , 'E' ...

  2. poj1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12507   Accepted: 6070 Des ...

  3. POJ1573——Robot Motion

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

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

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

  5. POJ1573(Robot Motion)--简单模拟+简单dfs

    题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...

  6. poj1573 Robot Motion(DFS)

    题目链接 http://poj.org/problem?id=1573 题意 一个机器人在给定的迷宫中行走,在迷宫中的特定位置只能按照特定的方向行走,有两种情况:①机器人按照方向序列走出迷宫,这时输出 ...

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

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

  8. HDU-1035 Robot Motion 模拟问题(水题)

    题目链接:https://cn.vjudge.net/problem/HDU-1035 水题 代码 #include <cstdio> #include <map> int h ...

  9. 模拟 POJ 1573 Robot Motion

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

随机推荐

  1. 面向新手的Webserver搭建(一)——IIS的搭建

    非常多童鞋说自己是做移动开发的,想挂个简单的Web API,但是server又不会搭,这样一来測试就成了问题.看看网上的教程.发现略难懂,并且大多是一个转一个,没价值,所以干脆写几篇文章讲讲简单的We ...

  2. 老鸟的Python新手教程

    重要说明 这不是给编程新手准备的教程,假设您入行编程不久,或者还没有使用过1到2门编程语言,请移步!这是有一定编程经验的人准备的.最好是熟知Java或C,懂得命令行,Shell等.总之,这是面向老鸟的 ...

  3. [AngularJS] Use ng-model-options to limit $digest

    Refer: http://toddmotto.com/super-fast-angular-ng-model-options-limit-digest-cycles/ Use: <input ...

  4. Android学习小Demo一个显示行线的自定义EditText

    今天在处理一个EditText的时候,想着把EditText做成像一本作业本上的纸一样,每一行都可以由线条隔开,具体效果如下: 1)最开始的思路 一开始的想法是很简单的,找出每一行的高度,然后一行一行 ...

  5. MySQL的字符编码体系(二)——传输数据编码

    MySQL的字符编码体系能够分成两部分:一部分是关于数据库server本身存储数据表时怎样管理字符数据的编码:还有一部分是关于client与数据库server数据传输怎样编码.上一篇MySQL的字符编 ...

  6. 一种解决的方法:CGContextSaveGState: invalid context 0x0

    遇到这个问题找了好久答案,最后排错排出来了 CGContextSaveGState: invalid context 0x0. This is a serious error. This applic ...

  7. Need a code of lazy load for div--reference

    1. For all DIVs of a page $(function() {  $("div").lazyload({effect: 'fadeIn'});}); 2. For ...

  8. 优雅退出 Android 应用程序的 6 种方式

    我们先来看看几种常见的退出方法(不优雅的方式) 一.容器式 建立一个全局容器,把所有的Activity存储起来,退出时循环遍历finish所有Activity import java.util.Arr ...

  9. noip 2012 借教室 (线段树 二分)

    /* 维护区间最小值 数据不超int 相反如果long long的话会有一组数据超时 无视掉 ll int */ #include<iostream> #include<cstdio ...

  10. LINQ:使用Take和Skip实现分页

    随便找的,还没有试过代码. class Program { static int Main() { //每页大小 ; //页码 ; //源数据 string[] names = { "贤静& ...