Given seven dart positions forming a simple polygon in some unknown order and the win probability of a random three-dart throw, find the dart order that matches it.
Medium6GeometryBrute forceImplementationNo attempts yetTime limit2sMemory limit512 MBIn the game of Unusual Darts, Alice throws seven darts at a board that measures 2 feet by 2 feet. Bob then throws three darts, or gets no throw at all.
The order in which Alice threw her darts defines one polygon. Its boundary runs from dart 1 to dart 2 to dart 3 to dart 4 to dart 5 to dart 6 to dart 7 and back to dart 1. If the polygon defined this way is not simple, meaning its boundary crosses itself, Alice loses. If it is simple, Bob throws three darts. Bob is not a good player, so his darts always land on the board, but they land at random on it following a uniform distribution. If all three darts land in the interior of the polygon, Bob wins, otherwise Alice wins.
A polygon is simple when two different edges meet only at the vertex shared by consecutive edges. Three darts on one straight line are allowed, as long as the boundary does not cross or overlap itself.
You are given the positions of Alice's seven darts and the probability that Bob wins. The given positions form a simple polygon. Determine the order in which Alice threw her darts.

The first line contains the number of dart games N (1≤N≤1000). Each game takes 8 lines. Lines 1 through 7 each contain two real numbers written with 3 digits after the decimal point, giving the x and y coordinates of Alice's seven darts, from x1 y1 to x7 y7. The seven positions are all different. Coordinates are in feet and satisfy 0≤xi,yi≤2. Line 8 contains a real number p written with 5 digits after the decimal point, the probability that Bob wins. In every game Alice's darts form a simple polygon, but not necessarily in the order given. At least one order matches the given probability.
For each game, print an order in which Alice could have thrown the darts, as the seven input numbers separated by single spaces on one line. An order counts as correct when the probability that Bob wins for the polygon it defines differs from p by at most 10−5. If several orders are correct, print the lexicographically smallest one.