1708. Connected Gheeves

单点时限: 2.0 sec

内存限制: 256 MB

Gheeves (plural of gheef) are some objects similar to funnels. We define a gheef as a two dimensional object specified by a sequence of points with the following conditions:

  1. If a point is specified by the coordinates , there is an index such that and . is called the cusp of the gheef.

  2. For all , and for all , .

  3. For , the amount of rotation required to rotate around in clockwise direction to become co-linear with and , is greater than 180 degrees. Likewise, for , the amount of rotation required to rotate around in clockwise rotation to become co-linear with and , is greater than 180 degrees.

  4. The set of segments joining two consecutive points of the sequence intersect only in their endpoints.

For example, the following figure shows a gheef of six points with :

We call the sequence of segments , the body of the gheef. In this problem, we are given two gheeves and , such that all coordinates of are negative integers and all coordinates of are positive integers. Assuming the cusps of the two gheeves are connected with a narrow pipe, we pour a certain amount of water inside the gheeves. As we pour water, the gheeves are filled upwards according to known physical laws (the level of water in two gheeves remains the same). Note that in the gheef , if the level of water reaches , the water pours out of the gheef (the same is true for the gheef ). Your program must determine the level of water in the two gheeves after pouring a certain amount of water. Since we have defined our problem in two dimensions, the amount of water is measured in terms of area it fills. Note that the volume of pipe connecting cusps is considered as zero.

输入格式

The first number in the input line, t is the number of test cases. Each test case is specified on three lines of input. The first line contains a single integer which specifies the amount of water poured into two gheeves. The next two lines specify the two gheeves and respectively, each of the form where is the number of points in the gheef ( for and for ), and the sequence specify the coordinates of the points in the sequences.

输出格式

The output contains t lines, each corresponding to an input test case in that order. The output line contains a single integer L indicating the final level of water, expressed in terms of y coordinates rounded to three digits after decimal points.

样例

Input
2
25
3 -30 10 -20 0 -10 10
3 10 10 20 0 30 10
25
3 -30 -10 -20 -20 -10 -10
3 10 10 20 0 30 10
Output
3.536
-15.000

114 人解决,125 人已尝试。

192 份提交通过,共有 461 份提交。

2.6 EMB 奖励。

创建: 12 年,4 月前.

修改: 2 年前.

最后提交: 1 周,2 天前.

来源: Tehran 2006 Preliminary

题目标签