题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=3085
分析
从男孩和女孩的起点开始分别BFS,男孩每次扩展三层,女孩每次扩展一层,且保证每一时刻 t t t 到鬼的曼哈顿距离不超过 2 ∗ t 2 * t 2∗t。
注意是鬼先走,当某次扩展到的节点对方已经走过,说明两人相遇。
AC代码
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
inline int read() {
int num = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9')
num = num * 10 + c - '0', c = getchar();
return num;
}
const int maxn = 805;
const int nxt[4][2] = {
{
-1, 0}, {
1, 0}, {
0, -1}, {
0, 1}};
struct Node {
int x, y;
Node(int x