A1391 | [COCI-2020-2021-contest5]#2 Planine
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Zoran wanders across his Dalmatian homeland to forget his love woes. He came across a mountain of a specific shape, behind which a young maiden is waiting for him. The mountain can be described with n alternating low and high points, where n is odd. Points at odd indices, except the first and the last point, are called valleys.
Zoran is afraid of the dark. Even the call of love will not give him courage to cross the mountain at night.
As usual, the fairies of Velebit come to the rescue.
We model each fairy by a luminous dot at a fixed height h. A fairy illuminates the valley if and only if the segment connecting the fairy and the valley does not intersect the interior of the mountain.
The mountain from the first example, and a fairy illuminating all three valleys.
What is the least number of fairies which can illuminate all the valleys simulaneously?
Zoran is afraid of the dark. Even the call of love will not give him courage to cross the mountain at night.
As usual, the fairies of Velebit come to the rescue.
We model each fairy by a luminous dot at a fixed height h. A fairy illuminates the valley if and only if the segment connecting the fairy and the valley does not intersect the interior of the mountain.
The mountain from the first example, and a fairy illuminating all three valleys.
What is the least number of fairies which can illuminate all the valleys simulaneously?
输入格式
The first line contains two integers n (3 ≤ n < 106 , n odd) and h (1 ≤ h ≤ 106 ), the number of points describing the mountain and the height the fairies live at.
The i-th of the following n lines contains integers xi and yi (−106 ≤ xi ≤ 106 , 0 ≤ yi < h), the coordinates of the i-th point of the mountain.
It is guaranteed that x1 < x2 < · · · < xn, and y1 < y2, y2 > y3, y3 < y4, . . ., yn−1 > yn.
The i-th of the following n lines contains integers xi and yi (−106 ≤ xi ≤ 106 , 0 ≤ yi < h), the coordinates of the i-th point of the mountain.
It is guaranteed that x1 < x2 < · · · < xn, and y1 < y2, y2 > y3, y3 < y4, . . ., yn−1 > yn.
输出格式
Output the least number of fairies such that all valleys are illuminated.
输入输出样例
输入 #1
9 6 0 0 1 2 3 0 6 3 8 1 9 2 11 1 12 4 14 0
输出 #1
1
Subtask Points Constraints
1 20 y2 = y4 = · · · = yn−1
2 30 3 ≤ n < 2000
3 60 No additional constraints.
Clarification of the examples:
The first example is shown in the statement.
It can be shown that the valleys in the second example cannot be illuminated using only one fairy. An
example with two fairies is given on the figure below.
1 20 y2 = y4 = · · · = yn−1
2 30 3 ≤ n < 2000
3 60 No additional constraints.
Clarification of the examples:
The first example is shown in the statement.
It can be shown that the valleys in the second example cannot be illuminated using only one fairy. An
example with two fairies is given on the figure below.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted