QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21104. 馬拉松

Statistics

Farmer John 不滿意乳牛健康欠佳,給牠們報名了各種健身活動。他的優秀乳牛 Bessie 參加了跑步課程,最終需要在農場附近城市的市中心跑一場馬拉松!

賽道包含必須依次經過的 $N$ 個檢查點,$3 \leq N \leq 500$。檢查點 1 是起點,檢查點 $N$ 是終點。Bessie 本應逐個經過所有檢查點,但她很懶,決定最多跳過 $K$ 個檢查點,$K<N$,來縮短路程。她不能跳過檢查點 1 或 $N$,否則太容易被發現。

請幫 Bessie 求出最多跳過 $K$ 個檢查點時所需跑的最短距離。

市中心街道呈網格狀,因此位於 $(x1, y1)$ 和 $(x2, y2)$ 的兩個檢查點間的距離為 $|x1-x2| + |y1-y2|$。

輸入格式

第一行給出 $N$ 和 $K$。

接下來 $N$ 行,每行包含兩個以空格分隔的整數 $x$ 和 $y$,表示一個檢查點($-1000 \leq x \leq 1000,$ $-1000 \leq y \leq 1000$)。檢查點按必須經過的順序給出。賽道可能多次自交,多個檢查點也可能位於同一個位置。跳過這樣的檢查點時,Bessie 只跳過該次出現,而不是跳過同一位置的所有檢查點。

輸出格式

輸出最多跳過 $K$ 個檢查點時的最短距離。在此範例中,跳過 $(8, 3)$ 和 $(10, -5)$ 的檢查點能得到最短總距離 4。

範例

輸入格式 1

5 2
0 0
8 3
1 1
10 -5
2 2

輸出格式 1

4

題目作者:Nick Wu,2014

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.