Given N vertical segments at increasing x, pick A on segment 1 and B on segment N uniformly; find the probability that chord AB crosses every segment.
Medium7GeometryProbabilityMathNo attempts yetTime limit0.5sMemory limit256 MBLittle Luka likes to doodle in his notebook during chemistry class. You can think of a page of his notebook as the coordinate plane.
This time Luka drew N segments parallel to the y-axis, all at different x coordinates. The segments are numbered from 1 to N in increasing order of their x coordinate.
Now Luka wants to draw one more segment AB that crosses all N segments, so that his doodle looks like a fish bone.
Luka does not know how to find such a segment, so he decided to pick one at random. He places point A somewhere on segment 1 and point B somewhere on segment N.
During the random choice, every point of a segment is equally likely to be picked. More precisely, Luka picks A and B independently, each one uniformly from its own segment.
Write a program that computes the probability that segment AB touches every one of the N drawn segments.
The first line contains the number of segments N (2≤N≤1000).
Each of the next N lines contains three positive integers x, y1, and y2 (1≤x≤1000, 1≤y1<y2≤1000), the coordinates of a segment parallel to the y-axis. The segment joins the points (x,y1) and (x,y2). The segments are given in order of their numbers, that is, in increasing order of x.
Print on a single line the probability that segment AB touches every one of the N drawn segments. The probability is a real number between 0 and 1 inclusive. Round it to 10 digits after the decimal point and print exactly 10 digits after the decimal point.