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.