QOJ.ac

QOJ

実行時間制限: 6 s メモリ制限: 256 MB 満点: 100

#11290. 城堡

統計

一队寻宝猎人获得了一张城堡地牢的地图,上面标有通往巨大宝藏的路线。地图覆盖在一个矩形网格上,网格的顶点坐标均为整数。具体来说,左下角坐标为 $(0, 0)$,右上角坐标为 $(w, h)$。整个地牢区域被划分为 $n$ 个房间;在地图上,每个房间都是一个边与网格线平行的矩形。这些矩形两两不相交,且完全覆盖了整个地图。如果两个房间的边共享一段公共线段(仅共享一个点是不够的),则它们之间可以通过通道连接。

寻宝猎人从一个网格点出发,宝藏隐藏在另一个网格点。我们希望确定寻宝猎人到达宝藏所需经过的最少房间数量。然而,地图上的一些房间带有神秘标记。虽然探险者不确定这些标记意味着什么,但他们预料到最坏的情况(例如陷阱),因此希望避开这些房间。

输入格式

第一行包含四个整数 $w, h, n$ 和 $m$ ($w, h \ge 2, n \ge 1, m \ge 0$),分别表示地图(网格)的尺寸、房间数量和标记数量。第二行包含一对整数 $x_P$ 和 $y_P$,表示寻宝猎人的起点。第三行包含一对整数 $x_S$ 和 $y_S$,表示宝藏的位置。

接下来的 $n$ 行描述房间:第 $i$ 行包含四个整数 $x_1, y_1, x_2, y_2$,表示代表第 $i$ 个房间的矩形的对角顶点坐标为 $(x_1, y_1)$ 和 $(x_2, y_2)$。

接下来的 $m$ 行描述标记:第 $i$ 行包含一对整数 $x$ 和 $y$,表示第 $i$ 个标记的坐标。

所有坐标均为整数,且满足以下不等式:$0 \le x \le w, 0 \le y \le h$。此外,寻宝猎人的初始位置、宝藏位置以及每个标记点都严格位于某个代表房间的矩形内部。

输出格式

输出一个整数:从点 $(x_P, y_P)$ 到点 $(x_S, y_S)$ 且不经过任何带有标记的房间的路径上,所需经过的最少房间数量。你可以假设这样的路径总是存在的。

样例

输入格式 1

7 6 8 2
1 1
6 4
0 0 3 2
3 1 6 3
3 0 7 1
6 1 7 3
0 2 3 6
3 3 5 5
3 5 5 6
5 3 7 6
5 2
4 4

输出格式 1

4

样例评分测试

  • 1ocen:地牢中只有一个房间,答案为 1;
  • 2ocen:有 1 000 000 个房间排成一行,没有房间被标记,答案为 1 000 000;
  • 3ocen:有 1000 × 1000 个房间均匀分布在一个正方形区域内,标记强制要求走一条螺旋路径。

评分

测试集由以下子任务组成。在每个子任务内,可能包含多个测试组。令 $W = 1\,000\,000\,000$,$N = 1\,000\,000$。

子任务 约束条件 分值
1 $w, h \le 2000, n, m \le 1000$ 10
2 $w, h \le 2000, n, m \le N$ 15
3 $w, h \le W, n, m \le 1000$ 15
4 $w, h \le W, n \le N, m = 0$ 30
5 $w, h \le W, n, m \le N$ 30

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.