Given N distinct points, find the probability that two independently drawn points lie on a 45-degree diagonal from each other.
Medium4Hash mapMathCombinatoricsNo attempts yetTime limit2sMemory limit512 MBGo Northwest! is a game that visitors play in the park main hall when rain keeps them away from the outdoor attractions.
Two people play it, and the result is pure luck. Neither player can do much about the outcome.
A large map on the wall shows N distinct towns. Before the game starts, the leader hands each player a bowl that holds N identical balls. Each ball names one town on the map, and every bowl contains all the towns exactly once.
When the game starts, one player draws a ball at random from his or her own bowl, opens it and reveals the town inside. Then the other player draws a ball at random from his or her own bowl and reveals the town inside.
If both towns are the same, the game is a draw. If the towns differ, the leader marks both of them on the map. If one town lies exactly northwest of the other, the first player wins. If one town lies exactly northeast of the other, the second player wins. Every other case is a draw. Two towns lie exactly northwest or northeast of each other when the angle between the line joining them and the horizontal axis is exactly 45 degrees.
The chance of a win depends on how the towns are laid out. All town coordinates are known in advance. Find the probability that the game has a winner.
The input holds several test cases and ends at end of file. Each test case starts with a line containing one integer N (1≤N≤105), the number of towns on the map. Each of the next N lines contains two integers x and y separated by a space, the coordinates of one town. The coordinates are standard Cartesian coordinates in the plane, and the absolute value of each coordinate is at most 109. The N towns of one test case are pairwise distinct. The sum of N over all test cases is at most 5×105.
For each test case, print one line with the probability that the game has a winner, rounded to exactly six digits after the decimal point. Always print all six digits, trailing zeros included, and round a value that falls exactly halfway upward. A probability of 1/4 is printed as 0.250000.