POJ1573 Robot Motion(模拟)
题目链接。
分析:
很简单的一道题,
#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(模拟)的更多相关文章
- POJ-1573 Robot Motion模拟
题目链接: https://vjudge.net/problem/POJ-1573 题目大意: 有一个N*M的区域,机器人从第一行的第几列进入,该区域全部由'N' , 'S' , 'W' , 'E' ...
- poj1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12507 Accepted: 6070 Des ...
- POJ1573——Robot Motion
Robot Motion Description A robot has been programmed to follow the instructions in its path. Instruc ...
- [ACM] hdu 1035 Robot Motion (模拟或DFS)
Robot Motion Problem Description A robot has been programmed to follow the instructions in its path. ...
- POJ1573(Robot Motion)--简单模拟+简单dfs
题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...
- poj1573 Robot Motion(DFS)
题目链接 http://poj.org/problem?id=1573 题意 一个机器人在给定的迷宫中行走,在迷宫中的特定位置只能按照特定的方向行走,有两种情况:①机器人按照方向序列走出迷宫,这时输出 ...
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- HDU-1035 Robot Motion 模拟问题(水题)
题目链接:https://cn.vjudge.net/problem/HDU-1035 水题 代码 #include <cstdio> #include <map> int h ...
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
随机推荐
- Android基础笔记(十四)- 内容提供者读取联系人
利用内容提供者读取联系人 利用内容提供者插入联系人 内容观察者的原理 利用内容观察者监听系统应用数据库或者自己应用数据库的变化 利用内容提供者读取联系人 读取联系人相对于读取短信来说就复杂非常多了,我 ...
- java 获取黑屏信息保存在list中,截取字符执行
ArrayList<String> list1 = new ArrayList<String>(); Process p = Runtime.getRuntime().exec ...
- [Angular 2] Adding a data model
Instead of add todo as a string, we create a data model: export class TodoModel{ constructor( public ...
- Linux - 标准输入转换为标准输出 代码(C)
标准输入转换为标准输出 代码(C) 本文地址:http://blog.csdn.net/caroline_wendy Linux能够使用getc()和putc(),读取和写入每个输入字符. 代码: / ...
- (转)void指针(void *的用法)
指针有两个属性:指向变量/对象的地址和长度 但是指针只存储地址,长度则取决于指针的类型 编译器根据指针的类型从指针指向的地址向后寻址 指针类型不同则寻址范围也不同,比如: int*从指定地址向后寻找4 ...
- [转] boost------ref的使用(Boost程序库完全开发指南)读书笔记
http://blog.csdn.net/zengraoli/article/details/9663057 STL和Boost中的算法和函数大量使用了函数对象作为判断式或谓词参数,而这些参数都是传值 ...
- Android(java)学习笔记245:ContentProvider使用(银行数据库创建和增删改查的案例)
1. Android的四大组件: (1)Activity 用户交互的UI界面 (2)Service 后台运行的服务 (3)BroadcastReceiver 广播接收者 (4)ContentPro ...
- android核心服务初探
终于进入android学习的进阶阶段,第一个课题是android的核心服务.首先,让我们来认识一下核心服务. android核心服务与app服务有所区别.app服务继承自Service基类,在app运 ...
- redis 中文手册
https://redis.readthedocs.org/en/latest/ http://www.cnblogs.com/ikodota/archive/2012/03/05/php_redis ...
- 解析JavaScript中apply和call以及bind
函数调用方法 在谈论JavaScript中apply.call和bind这三兄弟之前,我想先说下,函数的调用方式有哪些: 作为函数 作为方法 作为构造函数 通过它们的call()和apply()方法间 ...