#P15084. [ICPC 2024 Chengdu R] Two Convex Holes

[ICPC 2024 Chengdu R] Two Convex Holes

题目描述

Consider two opaque planes z=z1z = z_1 and z=z2z = z_2 (z1<z2z_1 < z_2) in a three-dimensional Cartesian coordinate system. Each plane has a convex polygonal hole, denoted as P1P_1 and P2P_2 respectively, which allows light to pass through.

There is a point light source LL moving in the plane z=z0z = z_0 (z2<z0z_2 < z_0), in a direction parallel to the xOyxOy plane. The light source starts at the initial position (x0,y0,z0)(x_0, y_0, z_0) at time t=0t = 0 and moves with a constant velocity v=(vx,vy,0)\boldsymbol{v} = (v_x, v_y, 0). Therefore, at any time tt, the position of the light source is given by (x0+vxt,y0+vyt,z0)(x_0 + v_x t, y_0 + v_y t, z_0).

For a point AA in the plane z=0z = 0, define it as illuminated\textbf{illuminated} at time tt if and only if the segment LALA intersects the interiors (including boundaries) of both polygons P1P_1 and P2P_2. The illuminated area\textbf{illuminated area} at time tt, denoted as f(t)f(t), is the area formed by all illuminated points in the plane z=0z = 0.

Define the average illuminated area\textbf{average illuminated area} over the time period [t1,t2][t_1, t_2], denoted as E[f(t)tU(t1,t2)]\mathbb{E}[f(t) | t \sim U(t_1,t_2)], as the expected value of f(t)f(t) over the interval [t1,t2][t_1, t_2], assuming tt is a uniformly distributed random variable over [t1,t2][t_1, t_2].

Given multiple time periods [t1,t2][t_1, t_2], your task is to find the average illuminated area for each of these periods.

输入格式

The first line contains a single integer TT (1T1041\le T\le 10^4) indicating the number of test cases.

For each test case, the first line contains five integers x0x_0, y0y_0, z0z_0, vxv_x, vyv_y (105x0,y0105-10^5 \le x_0, y_0 \le 10^5, 1z01051 \le z_0 \le 10^5, 103vx,vy103-10^3 \le v_x, v_y \le 10^3), representing the initial position of the light source (x0,y0,z0)(x_0, y_0, z_0) and its velocity vector v=(vx,vy,0)\boldsymbol{v} = (v_x, v_y, 0). It is guaranteed that v(0,0,0)\boldsymbol{v} \neq (0, 0, 0).

The second line contains two integers n1n_1 and z1z_1 (3n11053 \le n_1 \le 10^5, 1z11051 \le z_1 \le 10^5), indicating the number of vertices of polygon P1P_1 and the value of z1z_1. Each of the following n1n_1 lines contains two integers xix_i and yiy_i (105xi,yi105-10^5 \le x_i, y_i \le 10^5), describing the vertices of P1P_1 in counterclockwise order.

The following line contains two integers n2n_2 and z2z_2 (3n21053 \le n_2 \le 10^5, 1z21051 \le z_2 \le 10^5), indicating the number of vertices of polygon P2P_2 and the value of z2z_2. Each of the following n2n_2 lines contains two integers xjx_j and yjy_j (105xj,yj105-10^5 \le x_j, y_j \le 10^5), describing the vertices of polygon P2P_2 in counterclockwise order.

It is guaranteed that no three or more vertices are collinear for P1P_1 and P2P_2.

The following line contains an integer qq (1q1051 \le q \le 10^5), indicating the number of queries. Each of the following qq lines contains two integers t1t_1 and t2t_2 (0t1t21030 \le t_1 \le t_2 \le 10^3), representing a time period.

It is guaranteed that the sum of n1+n2n_1+n_2 and the sum of qq over all test cases do not exceed 10510^5, respectively, and z1<z2<z0z_1 < z_2 < z_0.

输出格式

For each query, output a real number representing the average illuminated area. Your answer will be considered correct only if the relative or absolute error between your answer and the correct answer does not exceed 10410^{-4}.

1
0 0 3 0 -1
4 1
1 0
3 0
3 2
1 2
4 2
0 0
1 0
1 1
0 1
3
0 10
1 2
1 1
0.450000000
1.125000000
2.250000000

提示

For the example, the projections of convex polygons P1P_1 and P2P_2 onto the xOyxOy plane at t=0t=0, and the movement of these projections, are illustrated below. Polygon A1B1C1D1A_1B_1C_1D_1 is the projection of polygon P1P_1, and polygon A2B2C2D2A_2B_2C_2D_2 is the projection of polygon P2P_2.

:::align{center} :::