题目链接

分析:

很简单的一道题,

#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. 玩转OpenStack网络Neutron(2)--使用Open vSwitch实现VLAN类型租户网络

    欢迎转载,转载请保留原作者信息 欢迎交流学习,共同进步! 作者:颜海峰 个人博客:http://yanheven.github.io 微博:海峰_云计算 http://weibo.com/344736 ...

  2. LayoutInflater和inflate()方法的使用方法

    public static LayoutInflaterfrom(Context context) { LayoutInflaterLayoutInflater = (LayoutInflater)c ...

  3. NSDateFormatter 格式说明

    格式化参数如下:    G: 公元时代,例如AD公元    yy: 年的后2位    yyyy: 完整年    MM: 月,显示为1-12    MMM: 月,显示为英文月份简写,如 Jan    M ...

  4. uva 10934 Dropping water balloons(转载)

    本文转载自http://blog.csdn.net/shuangde800/article/details/11273123 题意 你有k个一模一样的水球,在一个n层楼的建筑物上进行测试,你想知道水球 ...

  5. HUD 2444 The Accomodation of Students (二分图染色+最大匹配)

    #include<iostream> #include<cstdio> #include<cstring> #define maxn 2010 using name ...

  6. css font的简写规则

    font的属性简写里面常用的有5个是可以写在一起的: font-style设定斜体 如:font-style: italic;font-weight设定文字粗细 如:font-weight: bold ...

  7. java 跳转地址栏地址改变

    在strtus1 中,很多都是直接的action 配置后进行跳转的 这样地址栏是不会改变的 如果需要进行浏览器跳转 ActionForward actionForward = new ActionFo ...

  8. Phonegap 极光推送api 服务器端推送代码

    .net 版本 极光推送 后台接口 HttpWebResponseUtility类 using System; using System.Collections.Generic; using Syst ...

  9. [转]Delphi 中 image 控件加载bmp、JPG、GIF、PNG等图片的办法

    procedure TForm1.Button1Click(Sender: TObject); var jpg: TJPEGImage; // 要use Jpeg单元 begin // 显示jpg大图 ...

  10. javascript入门学习笔记

    <button type="button" onclick="alert('Welcome!')">点击这里</button>alert ...