QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 64 MB 満点: 100

#475. 青蛙

統計

Byteotia 爆发了蛙灾,庄稼惨遭破坏。农民 Byteasar 决定在田地里的某些位置放置奇特的“稻草蛙”来对抗这些害虫。青蛙在从一个位置移动到另一个位置时,会尽量远离这些稻草蛙,即最大化其到最近稻草蛙的距离。

Byteasar 的田地呈矩形。青蛙的跳跃方向与田地的边平行,且每次跳跃的长度为单位长度(长度为 $1$)。对于给定的青蛙路径,其“稻草蛙距离”定义为路径上所有跳跃点到所有稻草蛙的距离中的最小值。

Byteasar 已经掌握了青蛙最常见的起点和终点,因此他正在尝试各种稻草蛙的部署方案。他请求你编写一个程序,计算在给定的稻草蛙部署下,青蛙所能达到的最大“稻草蛙距离”(我们简称为“青蛙阈值距离”)。

任务

编写一个程序:

  • 从标准输入读取田地的大小、稻草蛙的坐标以及青蛙的起点和终点位置;
  • 确定青蛙阈值距离(即青蛙在能够到达终点的前提下,所能达到的最大稻草蛙距离);
  • 将该距离的平方输出到标准输出。

输入格式

第一行包含两个整数 $w_x$ 和 $w_y$,由空格分隔,表示田地的宽和长($2 ≤ w_x, w_y ≤ 1 000$)。 第二行包含四个整数 $p_x, p_y, k_x$ 和 $k_y$,由空格分隔;$(p_x, p_y)$ 是青蛙的初始位置,$(k_x, k_y)$ 是青蛙的目标(最终)位置($1 ≤ p_x, k_x ≤ w_x$, $1 ≤ p_y, k_y ≤ w_y$)。 第三行包含一个整数 $n$,表示田地上部署的稻草蛙数量($1 ≤ n ≤ w_x \cdot w_y$)。 接下来的 $n$ 行包含后续稻草蛙的坐标。第 $i+3$ 行($1 ≤ i ≤ n$)包含两个整数 $x_i$ 和 $y_i$,由空格分隔,表示第 $i$ 个稻草蛙的坐标($1 ≤ x_i ≤ w_x$, $1 ≤ y_i ≤ w_y$)。没有两个稻草蛙位于同一位置,且没有任何稻草蛙位于 $(p_x, p_y)$ 或 $(k_x, k_y)$ 点。

输出格式

在标准输出的第一行(也是唯一一行)输出一个整数,即青蛙阈值距离的平方。如果青蛙无法避免跳到某个稻草蛙上,则结果为 0。

样例

输入 1

5 5
1 1 5 5
2
3 3
4 2

输出 1

4

青蛙的最优路径。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.