POJ 1376 Robot
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7866 | Accepted: 2586 |
Description
The GO command has one integer parameter n in {1,2,3}. After receiving this command the robot moves n meters in the direction it faces.
The TURN command has one parameter which is either left or right. After receiving this command the robot changes its orientation by 90o in the direction indicated by the parameter.
The execution of each command lasts one second.
Help researchers of RMI to write a program which will determine the minimal time in which the robot can move from a given starting point to a given destination.
Input
Output
![](http://poj.org/images/1376_1.jpg)
Sample Input
9 10
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 1 0
7 2 2 7 south
0 0
Sample Output
12 这题改了好几天。。。。。
错误的点:
1.在DEBUG的时候我尝试恢复路径,此时发现有的结点的pre信息被后来修改,是因为应当在入队的时候标记,而不是出队的时候
2.对于位置的移动判断写错,首先边界不能触碰,而且一个黑色方格周围的点也不能。
3.在枚举一个点沿着一个方向行走的可行距离的时候,当遇到黑色方块或者边界的时候要break 代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 109
#define N 33
#define MOD 1000000
#define INF 1000000009
const double eps = 1e-;
const double PI = acos(-1.0); int X[] = { -,,, }, Y[] = { ,,,- };
bool been[MAXN][MAXN][];//四个方向
int n, m, rx, ry, g[MAXN][MAXN];
struct node
{
int x, y, dir, time;
node() = default;
node(int _x, int _y, int _dir, int _t) :x(_x), y(_y), dir(_dir), time(_t) {}
};
node pre[MAXN][MAXN][];
int d[MAXN][MAXN];
void print(node u)
{
vector<node> v;
for (;;)
{
//cout << u.x <<' '<< u.y << ' '<< u.dir << endl;
v.push_back(u);
if (u.time == ) break;
u = pre[u.x][u.y][u.dir];
}
int cnt = ;
for (int i = v.size() - ; i >= ; i--)
{
printf("%d %d %d %d\n", v[i].x, v[i].y, v[i].dir, v[i].time);
}
}
bool CanGo(int x, int y)
{
if (x< || x >= n || y< || y >= m)
return false;
if (g[x][y] || g[x + ][y] || g[x][y + ] || g[x + ][y + ])
return false;
return true;
}
int BFS(int x, int y, int d)
{
been[x][y][d] = true;
queue<node> q;
q.push(node(x, y, d, ));
while (!q.empty())
{
node t = q.front();
q.pop();
//cout << t.x << ' ' << t.y << ' ' << t.dir <<' ' << t.time << endl; if (t.x == rx&&t.y == ry)
{
//cout << t.prex << ' ' << t.prey << "::::" << t.dir << endl;
//print(t);
return t.time;
} if (!been[t.x][t.y][(t.dir + ) % ])
{
been[t.x][t.y][(t.dir + ) % ] = true;
pre[t.x][t.y][(t.dir + ) % ] = t;
q.push(node(t.x, t.y, (t.dir + ) % , t.time + ));
}
if (!been[t.x][t.y][(t.dir - + ) % ])
{
been[t.x][t.y][(t.dir - + ) % ] = true;
pre[t.x][t.y][(t.dir - + ) % ] = t;
q.push(node(t.x, t.y, (t.dir - + ) % , t.time + ));
}
for (int i = ; i <= ; i++)
{
int tx = t.x + X[t.dir] * i, ty = t.y + Y[t.dir] * i;
if (CanGo(tx, ty))
{
if(!been[tx][ty][t.dir])
{
been[tx][ty][t.dir] = true;
pre[tx][ty][t.dir] = t;
q.push(node(tx, ty, t.dir, t.time + ));
}
}
else
break;
}
}
return -;
}
int main()
{
while (scanf("%d%d", &n, &m), n + m)
{
memset(been, false, sizeof(been));
int tx, ty, d;
char op[];
for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
scanf("%d", &g[i][j]);
scanf("%d%d%d%d%s", &tx, &ty, &rx, &ry, op);
if (!CanGo(rx, ry))
{
printf("-1\n");
continue;
}
if (op[] == 'n')
d = ;
else if (op[] == 'e')
d = ;
else if (op[] == 's')
d = ;
else
d = ;
printf("%d\n", BFS(tx, ty, d));
}
}
POJ 1376 Robot的更多相关文章
- 模拟 POJ 1573 Robot Motion
题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...
- Robot POJ - 1376
The Robot Moving Institute is using a robot in their local store to transport different items. Of co ...
- POJ 1573 Robot Motion(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- POJ 1573 Robot Motion(模拟)
题目代号:POJ 1573 题目链接:http://poj.org/problem?id=1573 Language: Default Robot Motion Time Limit: 1000MS ...
- POJ 1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12978 Accepted: 6290 Des ...
- poj 1573 Robot Motion【模拟题 写个while循环一直到机器人跳出来】
...
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- poj 1573 Robot Motion_模拟
又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...
- poj 1367 robot(搜索)
题意:给你一个图,求起点 到 终点的最少时间 每次有两种选择①:往前走1~3步 ②原地选择90° 费时皆是1s 图中1为障碍物,而且不能出边界.还要考虑机器人的直径 ...
随机推荐
- Linux VPS上安装KDE, Gnome和VNC
- 元素类型以及overflow,white-space等属性
1:预格式化标签:<pre></pre>2:overflow属性="visible/hidden(隐藏)"/scroll/auto(自动)/inherit; ...
- [Swift通天遁地]五、高级扩展-(10)整形、浮点、数组、字典、字符串、点、颜色、图像类的实用扩展
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Oracle数据库初学者入门教程
Oracle数据库是相对于其他数据库来说比较难的一个.Oracle Database,又名Oracle RDBMS,简称Oracle.是甲骨文公司推出的一款关系数据库管理系统.Oracle数据库系统是 ...
- HTML--文本输入框、密码输入框
当用户要在表单中键入字母.数字等内容时,就会用到文本输入框.文本框也可以转化为密码输入框. 语法: <form> <input type="text/password&qu ...
- 【Codeforces866E_CF866E】Hex Dyslexia(Structure & DP)
It's my first time to write a blog in EnglishChinglish, so it may be full of mistakes in grammar. Pr ...
- Ambari架构及安装
不多说,直接上干货! 1.什么是Ambari? 2.Ambari项目是由哪几部分构成的? 3.Ambari系统架构是如何组成的? 前言 Hadoop集群的管控一直是一个热门的话题,对于这样的一个应用场 ...
- Laravel (5.5.33) 加载过程---make方法(四)
/** * Resolve the given type from the container. * * @param string $abstract * @return mixed */ publ ...
- wait、notify、notifyAll实现线程间通信
在Java中,可以通过配合调用Object对象的wait()方法和notify()方法或notifyAll()方法来实现线程间的通信.在线程中调用wait()方法,将阻塞等待其他线程的通知(其他线程调 ...
- html中设置浏览器解码方式
通过添加一行标签: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"& ...