QOJ.ac

QOJ

Límite de tiempo: 10 s Límite de memoria: 2048 MB Puntuación total: 100

#8778. 阴影线

Estadísticas

在二维平面上,原点处有一个点光源。在光源的右侧有一堵无限高的墙。光源与墙之间存在一些不透明的垂直线段。因此,每条线段都会在墙上投下阴影。所有这些阴影重叠在一起,在墙上形成一个或多个区间。

现在想象将光源沿 $x$ 轴向负方向移动,实际上是将光源沿直线进一步拉离所有物体。随着光源的移动,阴影也会随之移动,这可能会改变墙上阴影区间的数量。你的任务是计算光源在 $x$ 轴上哪些区间内移动时,墙上会形成单一的阴影区间,并求出这些区间长度的总和。

输入格式

第一行包含两个整数 $n$ ($1 \le n \le 3\,000$) 和 $w$ ($2 \le w \le 10^6$),其中 $n$ 是不透明垂直线段的数量,$w$ 是无限高墙的 $x$ 坐标。

接下来的 $n$ 行,每行包含三个整数 $x$ ($0 < x < w$),$y_{low}$ 和 $y_{high}$ ($-10^6 \le y_{low} < y_{high} \le 10^6$)。每组三个整数描述了一条从 $(x, y_{low})$ 到 $(x, y_{high})$ 的线段。所有 $y$ 坐标均不相同。任意两条线段都不会相交或重叠。

输出格式

输出一个数字,表示光源在 $x$ 轴上移动时,墙上形成单一阴影区间的区间长度总和。如果该总和包含无界区间(即当光源无限远时,墙上存在单一阴影区间),则输出 $-1$。如果你的答案与标准答案的绝对误差或相对误差在 $10^{-6}$ 以内,则会被接受。

样例

输入 1

3 20
2 1 3
6 -4 2
12 -10 -5

输出 1

16.0

Figure 1. Illustration of the point light source, opaque vertical segments, and the resulting shadows cast on the wall.

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.