QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 512 MB مجموع النقاط: 110

#13418. 山脉

الإحصائيات

Zoran 在他的达尔马提亚家乡漫步,以忘却他的情伤。他来到了一座形状独特的山前,山后面有一位年轻的姑娘在等着他。这座山可以用 $n$ 个高低交替的点来描述,其中 $n$ 是奇数。除了第一个和最后一个点外,奇数下标处的点被称为山谷

Zoran 怕黑。即使是爱情的呼唤也无法给他夜间翻越这座山的勇气。像往常一样,Velebit 的仙女们前来救援。

我们将每个仙女模型化为固定高度 $h$ 处的一个发光点。当且仅当连接仙女和山谷的线段不与山体内部相交时,仙女才能照亮该山谷。

第一个样例中的山,以及一个照亮所有三个山谷的仙女。

能够同时照亮所有山谷的仙女的最少数量是多少?

输入格式

第一行包含两个整数 $n$($3 \le n < 10^6$,$n$ 为奇数)和 $h$($1 \le h \le 10^6$),分别表示描述山体的点数和仙女居住的高度。

接下来的 $n$ 行中,第 $i$ 行包含两个整数 $x_i$ 和 $y_i$($-10^6 \le x_i \le 10^6$,$0 \le y_i < h$),表示山体第 $i$ 个点的坐标。

输入保证 $x_1 < x_2 < \dots < x_n$,且 $y_1 < y_2, y_2 > y_3, y_3 < y_4, \dots, y_{n-1} > y_n$。

输出格式

输出能够照亮所有山谷的仙女的最少数量。

子任务

子任务 分值 数据范围
1 20 $y_2 = y_4 = \dots = y_{n-1}$
2 30 $3 \le n < 2000$
3 60 无附加限制。

样例

输入样例 1

9 6
0 0
1 2
3 0
6 3
8 1
9 2
11 1
12 4
14 0

输出样例 1

1

输入样例 2

9 5
-5 2
-4 3
-2 1
0 4
2 2
3 3
4 1
5 2
6 1

输出样例 2

2

说明

第一个样例已在题目描述中给出。

可以证明,第二个样例中的山谷无法仅用一个仙女照亮。下图给出了使用两个仙女的示例。

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.