
ZOJ Problem Set  3928
Assuming that two points are chosen randomly (with uniform distribution) within a rectangle, it is possible to determine the expected value of the distance between these two points. It can be verified that, within a rectangle of sides a and b, the expected value of the distance between two random points is Now, point A is chosen randomly (with uniform distribution) within rectangle P, while point B is chosen randomly within rectangle Q similarly. Both sides of rectangle P and Q are parallel to the axes. Your task is to find the expected value of the distance between A and B. InputThere are multiple test cases. The first line of input is an integer T ≤10^{4} indicates the number of test cases. For each test case: There are 8 integers x_{1}, x_{2}, y_{1}, y_{2}, x_{3}, x_{4}, y_{3} and y_{4}. Rectangle P is {(x, y)  x_{1}≤ x≤ x_{2}, y_{1}≤ y≤ y_{2}} and rectangle Q is {(x, y)  x_{3}≤ x≤ x_{4}, y_{3}≤ y≤ y_{4}}. (0≤ x_{1}< x_{2}≤ 100, 0≤ y_{1}< y_{2}≤ 100, 0≤ x_{3}< x_{4}≤ 100, 0≤ y_{3}< y_{4}≤ 100) OutputFor each test case, output the expected value of the distance between A and B. Absolute error or relative error less than 10^{8} will be accepted. Sample Input2 0 1 0 1 0 1 0 1 1 2 3 4 5 6 7 8 Sample Output0.52140543316472 5.67158783860584 Author: ZHOU, Yuchen Source: The 16th Zhejiang University Programming Contest 