E. Corridor

Codeforces
IDCF82E
Time2000ms
Memory256MB
Difficulty
geometry
English · Original
Chinese · Translation
Formal · Original
Consider a house plan. Let the house be represented by an infinite horizontal strip defined by the inequality  - _h_ ≤ _y_ ≤ _h_. Strictly outside the house there are two light sources at the points (0, _f_) and (0,  - _f_). Windows are located in the walls, the windows are represented by segments on the lines _y_ = _h_ and _y_ =  - _h_. Also, the windows are arranged symmetrically about the line _y_ = 0. Your task is to find the area of the floor at the home, which will be lighted by the sources of light. <center>![image](https://espresso.codeforces.com/ee5b0785282dc1792169f0fd75524276e6bb12ee.png)</center> ## Input The first line of the input file contains three integers _n_, _h_ and _f_ (1 ≤ _n_ ≤ 500, 1 ≤ _h_ ≤ 10, _h_ < _f_ ≤ 1000). Next, _n_ lines contain two integers each _l__i_, _r__i_ ( - 5000 ≤ _l__i_ < _r__i_ ≤ 5000), each entry indicates two segments. Endpoints of the first segment are (_l__i_, _h_)\-(_r__i_, _h_), and endpoints of the second segment are (_l__i_,  - _h_)\-(_r__i_,  - _h_). These segments describe location of windows. Numbers in the lines are space-separated. It is guaranteed that no two distinct segments have common points. ## Output Print the single real number — the area of the illuminated part of the floor with an absolute or relative error of no more than 10 - 4. [samples] ## Note The second sample test is shown on the figure. Green area is the desired area of the illuminated part of the floor. Violet segments indicate windows.
考虑一个房屋平面图。 设房屋由不等式 $-h \leq y \leq h$ 定义的无限水平条带表示。在房屋外部严格之外,有两个光源位于点 $(0, f)$ 和 $(0, -f)$。窗户位于墙壁上,窗户由位于直线 $y = h$ 和 $y = -h$ 上的线段表示。此外,窗户关于直线 $y = 0$ 对称排列。 你的任务是求出房屋地板上被光源照亮的区域面积。 输入文件的第一行包含三个整数 $n$、$h$ 和 $f$($1 \leq n \leq 500$,$1 \leq h \leq 10$,$h < f \leq 1000$)。接下来的 $n$ 行每行包含两个整数 $l_i$、$r_i$($-5000 \leq l_i < r_i \leq 5000$),每条记录表示两个线段。第一个线段的端点为 $(l_i, h)$ 到 $(r_i, h)$,第二个线段的端点为 $(l_i, -h)$ 到 $(r_i, -h)$。这些线段描述了窗户的位置。行中的数字以空格分隔。保证任意两个不同的线段没有公共点。 输出一个实数——被照亮的地板部分的面积,绝对误差或相对误差不超过 $10^{-4}$。 第二个样例测试如图所示。绿色区域为所求的被照亮地板面积。紫色线段表示窗户。 ## Input 输入文件的第一行包含三个整数 $n$、$h$ 和 $f$($1 \leq n \leq 500$,$1 \leq h \leq 10$,$h < f \leq 1000$)。接下来的 $n$ 行每行包含两个整数 $l_i$、$r_i$($-5000 \leq l_i < r_i \leq 5000$),每条记录表示两个线段。第一个线段的端点为 $(l_i, h)$ 到 $(r_i, h)$,第二个线段的端点为 $(l_i, -h)$ 到 $(r_i, -h)$。这些线段描述了窗户的位置。行中的数字以空格分隔。保证任意两个不同的线段没有公共点。 ## Output 输出一个实数——被照亮的地板部分的面积,绝对误差或相对误差不超过 $10^{-4}$。 [samples] ## Note 第二个样例测试如图所示。绿色区域为所求的被照亮地板面积。紫色线段表示窗户。
**Definitions** Let $ n, h, f \in \mathbb{Z} $ with $ 1 \leq n \leq 500 $, $ 1 \leq h \leq 10 $, $ h < f \leq 1000 $. Let $ W = \{ (l_i, r_i) \mid i \in \{1, \dots, n\} \} $ be a set of $ n $ intervals, each defining a window segment on both top and bottom walls: - Top window: segment from $ (l_i, h) $ to $ (r_i, h) $ - Bottom window: segment from $ (l_i, -h) $ to $ (r_i, -h) $ Two point light sources are located at $ (0, f) $ and $ (0, -f) $. The house is the infinite horizontal strip $ \mathcal{H} = \{ (x, y) \in \mathbb{R}^2 \mid -h \leq y \leq h \} $. **Constraints** 1. All $ l_i, r_i \in \mathbb{Z} $, $ -5000 \leq l_i < r_i \leq 5000 $ 2. For all $ i \neq j $, intervals $ (l_i, r_i) $ and $ (l_j, r_j) $ are disjoint 3. $ h < f $ **Objective** Compute the area of the region $ \mathcal{I} \subseteq \mathcal{H} $ illuminated by at least one of the two light sources, where illumination occurs via rays passing through the windows. The illuminated region $ \mathcal{I} $ is the union of: - The region illuminated by source $ (0, f) $ through the top windows: $$ \mathcal{I}_+ = \bigcup_{i=1}^n \left\{ (x, y) \in \mathcal{H} \mid \exists t \in [0,1], \; (x, y) = (1-t)(l_i, h) + t(0, f) \text{ or } (x, y) = (1-t)(r_i, h) + t(0, f) \right\} $$ (i.e., the convex hull of $ (l_i, h), (r_i, h), (0, f) $ intersected with $ \mathcal{H} $) - The region illuminated by source $ (0, -f) $ through the bottom windows: $$ \mathcal{I}_- = \bigcup_{i=1}^n \left\{ (x, y) \in \mathcal{H} \mid \exists t \in [0,1], \; (x, y) = (1-t)(l_i, -h) + t(0, -f) \text{ or } (x, y) = (1-t)(r_i, -h) + t(0, -f) \right\} $$ Then: $$ \mathcal{I} = \mathcal{I}_+ \cup \mathcal{I}_- $$ Compute the area: $$ \text{Area} = \iint_{\mathcal{I}} dx\,dy $$
Samples
Input #1
1 1 2
-1 1
Output #1
10.0000000000
Input #2
2 2 4
-1 0
1 2
Output #2
23.3333333333
API Response (JSON)
{
  "problem": {
    "name": "E. Corridor",
    "description": {
      "content": "Consider a house plan. Let the house be represented by an infinite horizontal strip defined by the inequality  - _h_ ≤ _y_ ≤ _h_. Strictly outside the house there are two light sources at the points ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF82E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Consider a house plan.\n\nLet the house be represented by an infinite horizontal strip defined by the inequality  - _h_ ≤ _y_ ≤ _h_. Strictly outside the house there are two light sources at the points ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "考虑一个房屋平面图。\n\n设房屋由不等式 $-h \\leq y \\leq h$ 定义的无限水平条带表示。在房屋外部严格之外,有两个光源位于点 $(0, f)$ 和 $(0, -f)$。窗户位于墙壁上,窗户由位于直线 $y = h$ 和 $y = -h$ 上的线段表示。此外,窗户关于直线 $y = 0$ 对称排列。\n\n你的任务是求出房屋地板上被光源照亮的区域面积。\n\n输入文件的第一行包含三个整数 $n...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, h, f \\in \\mathbb{Z} $ with $ 1 \\leq n \\leq 500 $, $ 1 \\leq h \\leq 10 $, $ h < f \\leq 1000 $.  \nLet $ W = \\{ (l_i, r_i) \\mid i \\in \\{1, \\dots, n\\} \\} $ be a set of $ n $ inte...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments