CF1468G.Hobbits

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The hobbits Frodo and Sam are carrying the One Ring to Mordor. In order not to be spotted by orcs, they decided to go through the mountains.

The mountain relief can be represented as a polyline with nn points (xi,yi)(x_i, y_i), numbered from 11 to nn (xi<xi+1x_i \lt x_{i + 1} for 1≤i≤n−11 \le i \le n - 1). Hobbits start their journey at the point (x1,y1)(x_1, y_1) and should reach the point (xn,yn)(x_n, y_n) to complete their mission.

The problem is that there is a tower with the Eye of Sauron, which watches them. The tower is located at the point (xn,yn)(x_n, y_n) and has the height HH, so the Eye is located at the point (xn,yn+H)(x_n, y_n + H). In order to complete the mission successfully, the hobbits have to wear cloaks all the time when the Sauron Eye can see them, i. e. when there is a direct line from the Eye to the hobbits which is not intersected by the relief.

The hobbits are low, so their height can be considered negligibly small, but still positive, so when a direct line from the Sauron Eye to the hobbits only touches the relief, the Eye can see them.

The Sauron Eye can't see hobbits when they are in the left position, but can see them when they are in the right position.

The hobbits do not like to wear cloaks, so they wear them only when they can be spotted by the Eye. Your task is to calculate the total distance the hobbits have to walk while wearing cloaks.

霍比特人弗罗多和山姆正携带着至尊魔戒前往魔多。为避免被半兽人发现,他们决定穿越山脉。

山脉的地貌可表示为一条由 nn 个点 (xi,yi)(x_i, y_i) 构成的折线,这些点从 11 编号至 nn(满足 xi<xi+1x_i \lt x_{i + 1},其中 1≤i≤n−11 \le i \le n - 1)。霍比特人从起点 (x1,y1)(x_1, y_1) 出发,需抵达终点 (xn,yn)(x_n, y_n) 才能完成使命。

问题在于:一座矗立着索伦之眼的高塔正监视着他们。该塔位于点 (xn,yn)(x_n, y_n),高度为 HH,因此索伦之眼的位置为 (xn,yn+H)(x_n, y_n + H)。为成功完成使命,霍比特人必须在索伦之眼能看见他们时始终披上斗篷——即当从索伦之眼到霍比特人的视线未被地貌折线阻挡时。

霍比特人身材矮小,其身高可视为可忽略不计的正数;因此,若从索伦之眼到霍比特人的视线恰好与地貌折线相切,则索伦之眼仍能看见他们。

当霍比特人处于左侧位置时,索伦之眼无法看见他们;但当他们处于右侧位置时,索伦之眼可以看见他们。

霍比特人不喜欢披斗篷,因此仅在可能被索伦之眼发现时才披上斗篷。你的任务是计算霍比特人披着斗篷所行走的总路程长度。

输入格式

The first line of the input contains two integers nn and HH (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5; 1≤H≤1041 \le H \le 10^4) — the number of vertices in polyline and the tower height.

The next nn lines contain two integers xi,yix_i, y_i each (0≤xi≤4⋅1050 \le x_i \le 4 \cdot 10^5; 0≤yi≤1040 \le y_i \le 10^4) — the coordinates of the polyline vertices. It is guaranteed that xi<xi+1x_i \lt x_{i + 1} for 1≤i≤n−11 \le i \le n - 1.

输入的第一行包含两个整数 nn 和 HH(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5;1≤H≤1041 \le H \le 10^4)—— 分别表示折线的顶点数量和塔的高度。

接下来的 nn 行,每行包含两个整数 xi,yix_i, y_i(0≤xi≤4⋅1050 \le x_i \le 4 \cdot 10^5;0≤yi≤1040 \le y_i \le 10^4)—— 表示折线各顶点的坐标。保证对所有 1≤i≤n−11 \le i \le n - 1,均有 xi<xi+1x_i \lt x_{i + 1}。

输出格式

Print one real number — the total distance the hobbits have to walk while wearing cloaks. Your answer will be considered correct if its absolute or relative error does not exceed 10−610^{-6} — formally, if your answer is aa, and the jury's answer is bb, your answer will be accepted if ∣a−b∣max⁡(1,b)≤10−6\dfrac{|a - b|}{\max(1, b)} \le 10^{-6}.

输出一个实数——霍比特人穿斗篷行走的总距离。若你的答案的绝对误差或相对误差不超过 10−610^{-6},则视为正确;形式化地说,若你的答案为 aa,而评测组的答案为 bb,则当 ∣a−b∣max⁡(1,b)≤10−6\dfrac{|a - b|}{\max(1, b)} \le 10^{-6} 时,你的答案将被接受。

输入输出样例

  • 输入#1

    6 10
    10 40
    20 10
    25 30
    30 15
    50 15
    65 30

    输出#1

    70.4034587602
  • 输入#2

    9 5
    0 0
    5 10
    15 10
    20 0
    25 11
    30 0
    35 10
    50 10
    60 5

    输出#2

    27.2787986124
  • 输入#3

    2 10000
    0 10000
    400000 0

    输出#3

    400124.9804748512

输入解题思路,AI测评打分。不知道怎么写?

首页