#P16092. [ICPC 2024 NAC] Shadow Line
[ICPC 2024 NAC] Shadow Line
题目描述
You have a point light source at the origin in the 2D plane. To the right there is an infinitely tall wall. There are some opaque vertical line segments between the light source and the wall. As a result, each line segment casts a shadow onto the wall. All of these shadows overlap to form one or more intervals on the wall.
:::align{center}
:::
Now imagine moving the light source along the -axis in the negative direction, effectively pulling the light further away from all the objects in a straight line. As the light source moves, the shadows move as well, potentially changing the number of shaded intervals on the wall. Your job is to compute the sum of the lengths of the intervals along the -axis for which the light source creates a single shaded interval on the wall.
输入格式
The first line of input contains two integers () and (), where is the number of opaque vertical segments, and is the -coordinate of the infinitely tall wall.
Each of the next lines contains three integers (), and (). Each set of three integers describes a line segment from to . All -coordinates will be unique. No two line segments will intersect or overlap.
输出格式
Output a single number, which is the sum of the lengths of the intervals along the -axis for which the light source creates a single shaded interval on the wall. If this sum includes an unbounded interval (i.e. there is a single shaded interval when the light source is infinitely far away), print instead. Your answer will be accepted if the absolute or relative error is within of the judge’s answer.
3 20
2 1 3
6 -4 2
12 -10 -5
16.0