这次题好难……我 100 的时候一共才 4 个还是 5 个人。
// map 是 n * m 的
// x 是救助点
// # 不能走
// 一条指令是一个数字
// 0123 代表 北东南西
// 如果目的地不能到达,必须等待下一条指令
// 一种贪心算法
// 1. 找到 x 的单源最短路径,然后选一个最远的 A ,这个 A 是人可能在的位置
// 2. 生成从 A 到 x 的最短路径,如果最短路不唯一,就生成最小的
// 3. 计算人目前可能的位置
// 4. 如果 x 是人唯一可能在的位置,停止,否则回到 1
// 思路
// 1. bfs 计算 x 到每个点的距离,同时生成最小距离树
// 2. 更新人可能的位置,如果人只能在 x 结束。
// 3. 找到其中所有距离大的位置,生成序列。
// 4. 选择其中最小的序列,回到 2 .
#include <bits/stdc++.h>
using namespace std;
int n, m, xx, xy;
vector<vector<int>> dist(105, vector<int>(105, -1));
vector<vector<int>> pre(105, vector<int>(105, 0));
vector<vector<bool>> possible(105, vector<bool>(105, true));
vector<vector<bool>> block(105, vector<bool>(105, false));
const int direction[4][2] = {
{
-1, 0}, {
0, 1}, {
1, 0}, {
0, -1}};
vector<int> seqence(int x, int y) {
vector<int> s;
while (x != xx or y != xy) {
s.push_back((pre[x][y] + 2) % 4);
x += direction[s.back()][0];
y += direction[s.back()][1];
}
return s;
}
void move(int &x, int &y, vector<int> &s) {
for

最低0.47元/天 解锁文章
334

被折叠的 条评论
为什么被折叠?



