QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 512 MB Total points: 100

#21160. 田地割草

Statistics

Farmer John 管理農場的各方面都很可靠,唯獨不擅長及時割草。實際上,他每天只能移動割草機一次。第 1 天從 $(x_1, y_1)$ 出發,第 $d$ 天沿直線線段割草到 $(x_d, y_d)$,在農場二維地圖上水平或垂直移動,即 $x_d = x_{d-1}$ 或 $y_d = y_{d-1}$。FJ 相鄰兩天的移動交替為水平和垂直。

FJ 進度太慢,尚未割完所有草,一些割過的草就可能重新長出來。第 $d$ 天割過的草在第 $d + T$ 天重新出現,因此路徑若與至少 $T$ 天前割過的路徑相交,他就會再次割同一點的草。為改進糟糕的割草策略,FJ 想統計這種情況發生的次數。

請統計 FJ 的路徑與以前割過且草已重新長出的線段相交的次數。只計算「垂直」相交,即水平線段與垂直線段的公共點,且該點不是任何一條線段的端點。

輸入格式

第一行包含 $N$($2 \leq N \leq 100,000$)和 $T$($1 \leq T \leq N$,$T$ 為偶數)。

接下來 $N$ 行描述第 $1 \ldots N$ 天割草機的位置。第 $i$ 行包含整數 $x_i$ 和 $y_i$,都是不超過 $1,000,000,000$ 的非負整數。

輸出格式

輸出上述交點數量,也就是 FJ 再次割到之前割過並已長回的草的次數。

範例

輸入格式 1

7 4
0 10
10 10
10 5
3 5
3 12
6 12
6 3

輸出格式 1

1

說明

這裡 FJ 在第 7 天與第 2 天割過的線段相交,該交點計數,其他交點不計數。

說明:本題放寬了限制,每個測試案例限時 5 秒,Python 和 Java 為 10 秒,記憶體為 512 MB。

題目作者:Chad Waters 和 Brian Dean

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.