QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#23331. 避难所

Statistics

二维平面上的 KOI 村有 $N$ 栋房屋,第 $i$ 栋房屋位于 $(X_i,Y_i)$。

第 $i$ 栋与第 $j$ 栋房屋之间的距离为 $|X_i-X_j|+|Y_i-Y_j|$,即两栋房屋的 $X$ 坐标差与 $Y$ 坐标差之和。例如,位于 $(1,6)$ 和 $(2,4)$ 的房屋相距 $(2-1)+(6-4)=3$。

problem_23331_deff0585bfdfeabceeaf8ceafffce951.png

KOI 村计划在 $K$ 栋房屋中设置避难所,让居民在灾难发生时安全撤离。考虑所有居民的安全,需要选择这 $K$ 栋房屋,使各房屋到最近避难所的距离中的最大值尽可能小,并求出此时最远房屋到避难所的距离。

下图是一个有 $5$ 栋房屋的村庄示例,房屋分别位于 $(1,5),(3,0),(3,3),(6,12),(8,9)$。

problem_23331_8cd680fea2cbc249fea162710d3ed8f2.png

假设要在该村设置 $2$ 个避难所。如果选择位于 $(3,0)$ 和 $(1,5)$ 的房屋,其余三栋房屋到最近避难所的距离分别为 $3,11,12$,最大距离为 $12$。

problem_23331_ddd46d198168ba770a17d984bbb13a7d.png

但是,如果选择位于 $(3,3)$ 和 $(6,12)$ 的房屋设置避难所,到最近避难所最远的房屋位于 $(8,9)$,与 $(6,12)$ 相距 $5$。无论怎样设置避难所,都无法使最大距离小于 $5$,因此所求距离为 $5$。

problem_23331_c11b86a1adfd6845fd6e2f0eb63e1681.png

给定 KOI 村各房屋的位置和要设置的避难所数量,求出在所有设置方案中,各房屋到最近避难所距离的最大值的最小可能值。

数据范围

  • 所有给定的数都是整数。
  • $1 \le K \le 3$
  • $K \le N \le 50$
  • $0 \le X_i \le 100\,000$
  • $0 \le Y_i \le 100\,000$
  • 任意两栋房屋的位置不同,即 $(X_1,Y_1),(X_2,Y_2),\ldots,(X_N,Y_N)$ 互不相同。

子任务

  1. ($5$ 分) $N=K+1$
  2. ($7$ 分) $K=1$, 对于所有 $i$($1 \le i \le N$),$X_i=i$ 且 $Y_i=0$。
  3. ($10$ 分) $K=1$
  4. ($18$ 分) $K=2$
  5. ($35$ 分) $K=3$, 对于 $1 \le i \le N-1$,$X_i<X_{i+1}$,且对于所有 $i$($1 \le i \le N$),$Y_i=0$。即 $X$ 按升序排列。
  6. ($25$ 分) $K=3$

输入格式

第一行给出以空格分隔的 $N$ 和 $K$。

接下来 $N$ 行给出房屋位置,其中第 $i$ 行($1 \le i \le N$)给出以空格分隔的 $X_i$ 和 $Y_i$。

输出格式

在第一行输出答案。

样例

输入格式 1

5 2
1 5
3 0
3 3
6 12
8 9

输出格式 1

5

输入格式 2

4 2
0 0
0 5
5 0
5 5

输出格式 2

5

输入格式 3

4 1
1 0
2 0
3 0
4 0

输出格式 3

2

输入格式 4

2 1
20 23
5 14

输出格式 4

24

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.