#P17709. [ICPC 2019 Nanjing R] Triangle

    ID: 20161 远端评测题 8000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>计算几何2019二分Special JudgeICPC南京

[ICPC 2019 Nanjing R] Triangle

Problem Description

One day, ABC and DD found a triangular wheat field, and they decide to cut it into two pieces with the same area with a segment. Because of various reasons, one of the endpoints of the division line is fixed at (px,py)(p_x, p_y). Now you are asked to find the other endpoint of the segment.

If the given endpoint does not lie on the boundary of the wheat field, the problem should be regarded as invalid. The other endpoint required should also locate on the boundary.

Input Format

The input provides several test cases and the first line of the input contains a single integer T (1≤T≤1000000)T~(1 \le T \le 1000000) indicating the number of cases.

For each test case, eight integers x1,y1,x2,y2,x3,y3,pxx_1, y_1, x_2, y_2, x_3, y_3, p_x and pyp_y are given in a line, where (x1,y1),(x2,y2)(x_1, y_1), (x_2, y_2) and (x3,y3)(x_3, y_3) describe the coordinates of vertices for the given triangle wheat field which are guaranteed to be not colinear, and (px,py)(p_x, p_y) is the given endpont of the segment. All coordinates are integers in the range [0,100000][0, 100000].

Output Format

For each test case, output the coordinate of the other endpoint of the division segment, or output the number -1 if the problem, in this case, is invalid.

Formally, if your answer is aa and the jury's answer is bb, then your answer will be considered correct if and only if ∣a−b∣max⁡{1,∣b∣}≤10−6\frac{|a - b|}{\max\{1, |b|\}} \le 10^{-6}.

2
0 0 1 1 1 0 1 0
0 0 1 1 1 0 2 0
0.500000000000 0.500000000000
-1