POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573
题目链接:http://poj.org/problem?id=1573
Default
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 14195 | Accepted: 6827 |
Description

A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are
N north (up the page)
S south (down the page)
E east (to the right on the page)
W west (to the left on the page)
For example, suppose the robot starts on the north (top) side of Grid 1 and starts south (down). The path the robot follows is shown. The robot goes through 10 instructions in the grid before leaving the grid.
Compare what happens in Grid 2: the robot goes through 3 instructions only once, and then starts a loop through 8 instructions, and never exits.
You are to write a program that determines how long it takes a robot to get out of the grid or how the robot loops around.
Input
Output
Sample Input
3 6 5
NEESWE
WWWESS
SNWWWW
4 5 1
SESWE
EESNW
NWEEN
EWSEN
0 0 0
Sample Output
10 step(s) to exit
3 step(s) before a loop of 8 step(s)
Source
题目大意:WESN分别代表四个方向,第三个数据代表第一行的第几个位置开始,如果能走出去则输出走了几步,如果不能走出去进入了循环则输出第几步进入了循环,循环有几步。按题目标准格式输出。
解题思路:水题,作个标记代表第几步,如果下一步被标记过了则退出循环输出,如果走出去了也退出循环。
AC 代码:
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL; char a[][];
int b[][]; int main()
{
//freopen("in.txt", "r", stdin);
int n,m,k;
while(cin>>n>>m,n&&m)
{
cin>>k;
mem(a,);
mem(b,);
for(int i=;i<=n;i++)
cin>>a[i]+;
int x=,y=k;
b[x][y]=;
int ans=;
int flag=;
while()
{
if(a[x][y]=='W')y--;
else if(a[x][y]=='S')x++;
else if(a[x][y]=='E')y++;
else if(a[x][y]=='N')x--;
if(x==||x==n+||y==||y==m+)
{
printf("%d step(s) to exit\n",ans);
break;
}
else if(b[x][y])
{
printf("%d step(s) before a loop of %d step(s)\n",b[x][y]-,ans-b[x][y]+);
break;
}
else
{
b[x][y]=++ans;
}
}
}
return ;
}
POJ 1573 Robot Motion(模拟)的更多相关文章
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- POJ 1573 Robot Motion(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- poj 1573 Robot Motion_模拟
又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- [ACM] hdu 1035 Robot Motion (模拟或DFS)
Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...
- PKU 1573 Robot Motion(简单模拟)
原题大意:原题链接 给出一个矩阵(矩阵中的元素均为方向英文字母),和人的初始位置,问是否能根据这些英文字母走出矩阵.(因为有可能形成环而走不出去) 此题虽然属于水题,但是完全独立完成而且直接1A还是很 ...
随机推荐
- Shell 变量详解教程之位置变量与预定义变量
Shell 变量分为3部分,分别是用户自定义变量.位置变量和预定义变量. 一. 自定义变量 那么,什么是变量呢?简单的说,就是让某一个特定字符串代表不固定的内容,用户定义的变量是最普通的Shell ...
- 如何使用 re模块的, spilt.
例: 这是一组 网卡的信息. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopb ...
- JVM 堆内存设置原理(转)
堆内存设置 原理 JVM堆内存分为2块:Permanent Space 和 Heap Space. Permanent 即 持久代(Permanent Generation),主要存放的是Java类定 ...
- L2-001. 紧急救援(迪杰斯特拉算法)
L2-001. 紧急救援 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国 ...
- go相关资料
1.go的调度2.go struct能不能比较 因为是强类型语言,所以不同类型的结构不能作比较,但是同一类型的实例值是可以比较的,实例不可以比较,因为是指针类型 3.go defer(for defe ...
- Codeforces 10D LCIS 求最长公共上升子序列及输出这个子序列 dp
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qq574857122/article/details/34430283 题目链接:点击打开链接 题意 ...
- 手把手教你如何安装使用webpack vue cli
1.安装node.js:https://nodejs.org/en/download/(看电脑的系统是多少位下载相应版本) 我下载的是Windows Installer(.msi) x64 2.打开c ...
- vue-mixins和vue高阶组件
我们在开发过程中,因为需求的变更,往往会遇见对现有组件的改造和扩展. 那么我们有什么方法对现有组件进行改造和扩展呢? 常见的我们可以使用mixins方式 下面就让我们来看一下怎么使用mixins方式对 ...
- python全栈开发教程目录
python入门到进阶 Python基础2——数据类型的操作 Python基础——函数入门 Python基础——函数进阶 Python基础——函数的装饰器 Python基础——函数的装饰器 Pytho ...
- 异步分布式队列Celery
异步分布式队列Celery 转载地址 Celery 是什么? 官网 Celery 是一个由 Python 编写的简单.灵活.可靠的用来处理大量信息的分布式系统,它同时提供操作和维护分布式系统所需的工具 ...