1046 - Minimum surface distance

Time Limit : 1 Second

Memory Limit : 64 MB

Submission: 50

Solved: 2

Description
Now we have a cuboid p = {x, y, z | 0 <= x <= L, 0 <= y <= W, 0 <= z <= H}, and its volume is L * W * H. There are two points A(x1, y1, z1) and B(x2, y2, z2) on the surface of the cuboid.
The minimum surface distance from point A to point B is defined as follows, the minimum distance you must walk from point A to point B via the surface of the cuboid.
You are asked to calculate the minimum surface distance from point A to point B,
Input
The first line of the input contains an integer t, giving the number of the test cases;
Each test case contains three lines:
The first line: L, W, H; the second line: x1, y1, z1, the third line: x2, y2, z2.
All the numbers are integers and in the range of 0 to 1000(both included).
Output
For each test case, output a line with the result, rounded to the second digit after the decimal point.
sample input
1
5 5 2
3 1 2
3 5 0
sample output
6.00
hint
source
lshmouse
© 2015 HUST ACMICPC TEAM. All Right Reserved.