QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#20127. 征服战役

Statistics

自 30 世纪初以来,Country of Circles 已成为世界上最强大的国家。为了向西扩张领土,他们计划入侵 Country of Rectangles。

Country of Rectangles 的领土用一个 $R\times C$ 的表格表示,行从 $1$ 到 $R$ 编号,列从 $1$ 到 $C$ 编号。第 $i$ 行、第 $j$ 列的格子记为 $(i,j)$。

Country of Circles 的国防部计划派出精锐伞兵部队进攻 Country of Rectangles。通过派遣间谍,他们得知 Country of Rectangles 中的 $N$ 个格子 $(x_1,y_1),(x_2,y_2),\ldots,(x_N,y_N)$ 防守非常薄弱,容易占领。因此,他们制定了如下计划:

  • 第一天,派出一个伞兵营占领这 $N$ 个格子中的每个格子。
  • 在随后的每一天,派出增援部队,占领所有与至少一个此前已占领的格子共边的格子。

我们假设 Country of Circles 的部队足够强大,可以占领任何他们想占领的格子。

指挥官想知道,征服整个国家需要多少天。

输入格式

  • 第一行包含三个整数 $R$、$C$ 和 $N$ ($1\le R,C\le100$,$1\le N\le10\,000$),分别表示 Country of Rectangles 领土的行数、列数以及防守薄弱的格子数。不保证这些格子互不相同。
  • 接下来的 $N$ 行中的第 $i$ 行包含两个整数 $x_i$ 和 $y_i$ ($1\le x_i\le R$,$1\le y_i\le C$),表示战役第一天派遣伞兵前往的一个格子。

输出格式

输出恰好一个数,表示 Country of Circles 完全征服 Country of Rectangles 所需的天数。

样例

输入格式 1

3 4 3
2 2
2 2
3 4

输出格式 1

3

说明

下图展示了计划每天的执行情况,其中:

  • 白色格子尚未被占领。
  • 带条纹的格子是当天占领的格子。
  • 纯色格子是之前几天占领的格子。
problem_20127_119402953f0da2fdf8d99efb649c8cf0.png

输入格式 2

2 3 6
1 1
1 2
1 3
2 1
2 2
2 3

输出格式 2

1

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.