#P4605. [SDOI2018] 物理实验

    ID: 3549 远端评测题 10000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2018各省省选平衡树山东Special JudgeO2优化前缀和向量

[SDOI2018] 物理实验

Description

Xiao T has a physics lab class this semester. To successfully finish the experiment in the next class, he plans to preview it before class.

This experiment is conducted on a 2D plane. On the plane there is an infinitely long straight guide rail. On the rail, there is a laser emitter of length LL. The laser emitter emits laser beams of width LL to both sides of the rail along the direction perpendicular to the rail.

There are also nn baffles on the plane. Each baffle can be regarded as a line segment. Now each baffle does not touch the straight guide rail, and the angle between it and the rail is at most 85°85\degree. Any two baffles also do not touch each other. The laser beams cannot pass through these baffles, and will be absorbed by them, not reflected.

Xiao T wants to determine a position of the laser emitter such that the total length of baffles illuminated by the laser beams is maximized. You need to help Xiao T compute this maximum value.

Input Format

The first line contains a positive integer TT, indicating the number of testdata groups.

For each testdata group, the first line contains an integer nn, indicating the number of baffles.
The next nn lines each contain four integers x1,y1,x2,y2x1, y1, x2, y2, indicating that the two endpoints of the baffle are (x1,y1)(x1, y1) and (x2,y2)(x2, y2), guaranteeing (x1,y1)=/(x2,y2)(x1, y1){=}\mathllap{/\,}(x2, y2).
The (n+2)(n + 2)-th line contains five integers x1,y1,x2,y2,Lx1, y1, x2, y2, L, indicating that the straight guide rail passes through points (x1,y1)(x1, y1) and (x2,y2)(x2, y2), and the length of the laser emitter is LL, also guaranteeing (x1,y1)/=(x2,y2)(x1, y1)\mathrlap{\,/}{=}(x2, y2).

Output Format

For each testdata group, output one line containing a real number, representing the maximum total length of baffles that can be illuminated by the laser beams. The relative error must not exceed 10610^{-6}, that is, let your output be aa and the standard answer be bb. If abmax(1,b)\dfrac{|a-b|}{max(1,b)} 10610^{-6}, then your output will be considered correct.

3
4
-3 2 -1 2
-1 -1 1 -1
0 1 2 1
2 -2 4 -2
0 0 1 0 2
4
1 1 3 3
2 1 4 2
3 1 5 1
3 -1 4 -1
0 0 -1 0 2
4
-2 0 1 2
1 3 -3 2
1 -3 5 -1
2 -1 4 3
0 0 1 1 2

3.000000000000000
3.118033988749895
4.251303782246768

Hint

Constraints

  • T100T ≤ 100.
  • 1n1041 ≤ n ≤ 10^4.
  • 1L2×1091 ≤ L ≤ 2 × 10^9.
  • The absolute value of all coordinates does not exceed 10910^9.

SubTasks

  • Subtask 1 (40 points): 1n1001 ≤ n ≤ 100 and the absolute value of all coordinates does not exceed 10410^4.
  • Subtask 2 (40 points): the absolute value of all coordinates does not exceed 10610^6.
  • Subtask 3 (20 points): no additional constraints.

Translated by ChatGPT 5