题目地址:http://poj.org/problem?id=1573

 /*
题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数
如果是死循环,输出走进死循环之前的步数和死循环的步数
模拟题:used记录走过的点,因为路线定死了,所以不是死循环的路只会走一次,可以区分出两个步数 注意:比较坑的是,如果不是死循环,临界(走进去就出来)步数是1;而死循环却是0. 这里WA几次。。。
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f;
int a[MAXN][MAXN];
int used[MAXN][MAXN]; void work(int n, int m, int k)
{
int ans = ; int cnt = ; int i = , j = k;
while (i >= && i <= n && j >= && j <= m)
{
if (used[i][j] <= )
{
switch (a[i][j])
{
case 'N': i -= ; break;
case 'S': i += ; break;
case 'W': j -= ; break;
case 'E': j += ; break;
}
used[i][j]++;
if (used[i][j] == ) cnt++;
else ans++;
}
else
{
int res = ans - cnt;
if (res == ) res = ;
printf ("%d step(s) before a loop of %d step(s)\n", res, cnt);
break;
}
}
if (i < || i > n || j < || j > m)
printf ("%d step(s) to exit\n", ans);
} int main(void) //POJ 1573 Robot Motion
{
//freopen ("H.in", "r", stdin); int n, m, k;
while (~scanf ("%d%d%d", &n, &m, &k) && n && m && k)
{
getchar ();
for (int i=; i<=n; ++i)
{
for (int j=; j<=m; ++j)
{
a[i][j] = getchar ();
}
getchar ();
} memset (used, , sizeof (used));
work (n, m, k);
} return ;
} /*
10 step(s) to exit
3 step(s) before a loop of 8 step(s)
*/

模拟 POJ 1573 Robot Motion的更多相关文章

  1. POJ 1573 Robot Motion(模拟)

    题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...

  2. poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】

                                                                                                         ...

  3. POJ 1573 Robot Motion(BFS)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12856   Accepted: 6240 Des ...

  4. POJ 1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12978   Accepted: 6290 Des ...

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

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

  6. Poj OpenJudge 百练 1573 Robot Motion

    1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...

  7. poj 1573 Robot Motion_模拟

    又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...

  8. PKU 1573 Robot Motion(简单模拟)

    原题大意:原题链接 给出一个矩阵(矩阵中的元素均为方向英文字母),和人的初始位置,问是否能根据这些英文字母走出矩阵.(因为有可能形成环而走不出去) 此题虽然属于水题,但是完全独立完成而且直接1A还是很 ...

  9. POJ 1573:Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11324   Accepted: 5512 Des ...

随机推荐

  1. CocoStudio基础教程(1)创建UI并载入到程序中

    1.概述 CocoStudio的使用无疑是cocos2d-x 3.0的重要组成部分,接下来我们用它来创建一组UI,并将其读入到程序中显示出来.先上效果图: 2.导出 在导出之前,最好先创建一个新的工程 ...

  2. Android EditText 文本框实现搜索和清空效果

    前言 本文实现的效果:文本框输入为空时显示输入的图标:不为空时显示清空的图标,此时点击清空图标能清空文本框内输入文字. 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnbl ...

  3. [Effective JavaScript 笔记]第33条:使构造函数与new操作符无关

    当使用函数作为一个构造函数时,程序依赖于调用者是否记得使用new操作符来调用该构造函数.注意:该函数假设接收者是一个全新的对象. 一个例子 function User(name,pwd){ this. ...

  4. mac安装django1.5.4

    http://www.iwangzheng.com/ 1.下载安装程序 打开终端输入以下命令 $ wget http://www.djangoproject.com/m/releases/1.5/Dj ...

  5. python代码中使用settings

    在具体的Django应用中,通过引入 django.conf.settings 使用配置,例: from django.conf import settings settings.configure( ...

  6. Rehashing

    The size of the hash table is not determinate at the very beginning. If the total size of keys is to ...

  7. sharepoint修改密码

    增加SharePoint2010修改域密码功能 前提SharePoint2010的用户基于AD的,因此修改密码是修改了AD的密码,当然也可以修改本机密码(非域的密码).这里我们讨论修改域密码.我们修改 ...

  8. iOS的 context 和Android 中的 canvas

    ios 想要绘图,要用到CGContextRef类.最基本的用法是在- (void)drawRect:(CGRect)rect 函数中绘制. Android 中要用到Canvas类.最基本的用法是在  ...

  9. Ubuntu下装QQ2014

    1.首先我们需要下载一个 deb的 Wine QQ安装包 qq2014官方下载:http://www.longene.org/download/WineQQ2013SP6-20140102-Longe ...

  10. OSG 初始化为非全屏窗口

    OSG默认的窗口时全屏的,调试的时候不方便. 在网上看到一段代码,可以非全屏显示 int _tmain(int argc, _TCHAR* argv[]){ osgViewer::Viewer vie ...