#P14189. [ICPC 2024 Hangzhou R] Catch the Star

    ID: 14062 Type: RemoteJudge 4000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2024Special JudgeICPC杭州

[ICPC 2024 Hangzhou R] Catch the Star

题目描述

BaoBao bought a telescope to observe a star in the night sky. The star is represented as a convex polygon SS. However, there are nn convex polygonal moons MiM_i that could obstruct his view. BaoBao can place his telescope anywhere on the xx-axis between points (l,0)(l,0) and (r,0)(r,0), but he cannot\textbf{cannot} place it exactly at (l,0)(l,0) or (r,0)(r,0).

Your task is to help BaoBao find the total length of the segments on the x-axis where he can position his telescope such that he has an unobstructed view of the star SS, and whether he can\textbf{can} find a position at all. An unobstructed view means that no line segment from the chosen point on the x-axis to any point inside or on SS properly intersects any of the moons MiM_i. The line segment is allowed to touch the boundary of the moons but not cross through them.

输入格式

There are multiple test cases. The first line of the input contains an integer TT (1T2.5×1041 \leq T \leq 2.5 \times 10^4) indicating the number of test cases. For each test case:

The first line contains three integers nn, ll, and rr (1n1041 \leq n \leq 10^4, 109l<r109-10^9 \leq l < r \leq 10^9), denoting the number of moons and the range for telescope placement.

The second line describes the star SS and begins with an integer k0k_0 (3k01053 \leq k_0 \leq 10^5), denoting the number of vertices of SS, followed by 2×k02 \times k_0 integers $x_{0,1},y_{0,1},x_{0,2},y_{0,2},\cdots,x_{0,k_0},y_{0,k_0}$ (109x0,j,y0,j109-10^9 \leq x_{0,j},y_{0,j} \leq 10^9), where (x0,j,y0,j)(x_{0,j},y_{0,j}) is the coordinate of the jj-th vertex of SS in counter-clockwise order.

For the following nn lines, the ii-th line describe moon MiM_i. Each line begins with an integer kik_i (3ki1053 \leq k_i \leq 10^5), denoting the number of vertices of MiM_i, followed by 2×ki2 \times k_i integers $x_{i,1},y_{i,1},x_{i,2},y_{i,2},\cdots,x_{i,k_i},y_{i,k_i}$ (109xi,j,yi,j109-10^9 \leq x_{i,j},y_{i,j} \leq 10^9), where (xi,j,yi,j)(x_{i,j},y_{i,j}) is the coordinate of the jj-th vertex of MiM_i in counter-clockwise order.

It is guaranteed that SS and MiM_i are convex polygons. The star SS, the moons MiM_i, and the segment from (l,0)(l,0) to (r,0)(r,0) do not touch or intersect with each other. However, different moons MiM_i can intersect with each other. No three consecutive vertices of the same polygon are collinear.

It's guaranteed that the sum of i=0nki\sum\limits_{i=0}^n k_i of all test cases does not exceed 10610^6. It is also guaranteed that the total number of polygons of all test cases (which is (n+1)\sum (n + 1)) does not exceed 5×1045 \times 10^4.

输出格式

For each test case, output a single line containing the total length of valid segments on the x-axis, strictly between (l,0)(l,0) and (r,0)(r,0), where BaoBao can place his telescope to see SS without obstruction. If there's no valid point between (l,0)(l,0) and (r,0)(r,0), output 1-1 instead.

Your answer would be considered correct if the relative or absolute error does not exceed 10910^{-9}.

2
4 -8 8
3 -7 7 -6 8 -7 8
3 -9 -2 -7 3 -9 -1
3 -2 3 0 2 -4 5
3 5 1 5 3 4 2
3 1 -1 2 -2 3 -1
5 -8 8
5 -14 -3 -10 -2 -9 2 -10 4 -12 5
3 -16 0 -15 0 -15 1
3 -15 6 -9 5 -15 7
3 -10 5 -9 5 -10 6
3 -7 3 -3 2 -8 4
3 -6 -1 -6 -2 -5 -1
9.404761904761905
6.000000000000000
3
1 -4 4
3 -2 6 0 5 2 6
3 -3 1 3 1 0 4
3 -2 2
3 -2 4 2 4 0 6
3 -2 2 -1 2 -2 3
3 1 2 2 2 2 3
3 -2 -1 0 -3 2 -1
1 1 2
3 -8 0 -7 0 -8 1
3 -5 0 -4 -1 -4 0
-1.000000000000000
0.000000000000000
1.000000000000000
1
1 -744567334 955216804
5
-781518205 -852078097
-781516900 -852078384
-781516392 -852076569
-781518329 -852076047
-781519925 -852077600
5
-393011614 -131855702
-393010699 -131856607
-393008846 -131856475
-393009388 -131854587
-393010201 -131854694
1699779738.691979192313738

提示

For the first sample, the first test case is illustrated below; the telescope can be located between (7,0)(-7,0) and (23,0)(-\frac{2}{3},0), or (72,0)(\frac{7}{2},0) and (467,0)(\frac{46}{7},0).

:::align{center} :::

The second test case is illustrated below; the telescope can be located between (8,0)(-8,0) and (2,0)(-2,0).

:::align{center} :::

Note that the input format in the third sample is for presentation purposes only, because we cannot print all the coordinates in one line without exceeding the width of the paper. Please refer to the other samples for more accurate input formatting.