题目地址: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. GDB 使用大法

    一.GDB 我用的是 GCC+POWERSHELL+GDB,  GDB刚刚接触也有很多要记的. 二.一个调试示例 tst.c #include <stdio.h> int func(int ...

  2. Linux 守护进程和超级守护进程(xinetd)

    一 .Linux守护进程 Linux 服务器在启动时需要启动很多系统服务,它们向本地和网络用户提供了Linux的系统功能接口,直接面向应用程序和用户.提供这些服务的程序是由运行在后台的守护进程来执行的 ...

  3. nyoj 8

    http://acm.nyist.net/JudgeOnline/problem.php?pid=8 #include<stdio.h> #include<iostream> ...

  4. 《linux备份与恢复之一》.tar.bz2与.tar.gz格式的文本压缩率比较

    对于文本压缩,据说bzip的算法要优于gzip,从而拥有更好的压缩比.特地找了两个文件来做一下测试,以下为测试结果:   (1)源文件为591MB, .tar.bz2文件为61MB(10.32%), ...

  5. ENGINE=InnoDB

    最开始用MySQL Administrator建数据库的时候,表缺省是InnoDB类型,也就没有在意.后来用Access2MySQL导数据的时候发现只能导成 MyISAM类型的表 区别如下原来是MyI ...

  6. TokuDB的特点验证

    随着数据量越来越大,越来越频繁的遇到需要进行结构拆分的情况,每一次拆分都耗时很久,并且需要多方配合,非常的不想搞这个事情.于是在@zolker的提醒下想到了13年开源tokuDB,来解决我们迫在眉睫的 ...

  7. Java for LeetCode 066 Plus One

    Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...

  8. poj 3750 小孩报数问题 解题报告

    题目链接:http://poj.org/problem?id=3750 约瑟夫问题,直接模拟即可. #include <iostream> #include <string> ...

  9. jquery记住密码,记住账号,自动登录

    1.引入jquery库 2.引入jquery.cookie.js库 3.引入操作js jsp如下: $(document).ready(function() { //输入框获得焦点-失去焦点 $(&q ...

  10. July 20th, Week 30th Wednesday, 2016

    Learn from yesterday, live for today, and hope for tomorrow. 借鉴昨天,活着当下,憧憬未来. Yesterday is the past, ...