QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 1024 MB Puntuación total: 100

#23331. 避難所

Estadísticas

二維平面上的 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.