PAT(甲级)2022 年春季 7-4

这次题好难……我 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 
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值