题目地址: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. IIS假死状态处理

    为应用程序池 'DefaultAppPool' 提供服务的进程关闭时间超过了限制  服务器经常产生“应用程序池 'DefaultAppPool' 提供服务的进程关闭时间超过了限制.进程 ID 是 '2 ...

  2. MySQL sql语句总结

    1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数据的 d ...

  3. Python配合BeautifulSoup读取网络图片并保存在本地

    本例为Python配合BeautifulSoup读取网络图片,并保存在本地. BeautifulSoup可代替正则表达式,更好地解析Html文本,获取其中的指定内容,如Tag.Property等 # ...

  4. MongoDB 学习笔记(python操作)

    转自: http://blog.csdn.net/daillo/article/details/7030910

  5. Gson简要使用

    哇,原来我已经潜水2年多了,还是需要养成习惯写写东西啊. 最近在做一个java web service项目,需要用到jason,本人对java不是特别精通,于是开始搜索一些java平台的json类库. ...

  6. 《ASP.NET1200例》C# WINFORM程序的三层架构如何建立的。

    先添加-新建项目-windows应用程序,然后在右边的解决方案资源管理器上面,在当前的解决方案上面右击,点,添加-新建项目-类库,分别建立.DAL,BLL,Model三个项目,然后,在DAL项目上右击 ...

  7. spring无法扫描jar包的问题

    在日常开发中往往会对公共的模块打包发布,然后调用公共包的内容.然而,最近对公司的公共模块进行整理发布后.spring却无法扫描到相应的bean.折腾了好久,最终发现是认识上的误区. 2015-11-1 ...

  8. 关于https和数字证书的一些必须知识

    下面这篇文章叫做  HTTPS连接的前几毫秒发生了什么 ,是一篇译文,写得不错,十分有助于理解https. http://blog.jobbole.com/48369/ 下面的链接是百度文库的 数字证 ...

  9. 当年的文曲星cc800

    你还记得当年的cc800吗?还记得黄金英雄传说吗?还记得用cc800编程的日子吗... 今天突然想起了我的cc800,好怀念那段爬在家里的阳台的木架子上,挠着头,编程序的日子...可惜,当时比较穷,没 ...

  10. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...