Problem F
Hidden Triangles
Input: Standard Input
Output: Standard Output
Figure 1: |
If x1down=0, x2down=2, x1up=0 and x2up=2 and h=1 then nine such triangles are formed.. All these triangles are filled black in Figure 2.
Figure 2: Formed nine triangles are shown by filling them with black. |
When number of lattice points on the lines are very small, then such triangles are very easy to count, but for large number of lattice points such triangles are hard to count, let alone measuring the average height of such triangles.
In this problem you have to do this mammoth task. Given the values of x1down, x2down, x1up, x2up and h your job is to find the average height of all the triangles formed whose base is x-axis and height is less than h.
The input file contains at most 5001 lines of inputs. Each line contains five integer numbers x1down, x2down (0≤x1down<x2down≤100000 and |x1down-x2down|≤10000), x1up, x2up (0≤x1up<x2up≤100000 and |x1up-x2up|≤10000) and h (0<h≤10).
Input is terminated by a line containing five zeroes.
For each line of input produce one line of output. This line contains the serial of output followed by a floating-point number which denotes the average height of the formed triangles. The floating point number should have six digits after the decimal point. Errors less than 1.5*10-6.will be ignored. Look at the output for sample input for details.
5 8 5 7 1 0 2 0 2 1 0 100 0 101 1 0 0 0 0 0 |
Case 1: 0.542593 Case 2: 0.500000 Case 3: 0.498223
|
Problemsetter: Shahriar Manzoor
Special Thanks: Derek Kisman