This page is still under construction.

Parts of this page are still being built. What you see may change.

Stacking Curvy Blocks

Time limit2sMemory limit256 MB

Summary
Given two cubic edges on [0,1], lower the upper curve until it touches the lower one and report the largest vertical gap between them.
Level

Medium4 of 10

Topics
Math
Solved
No attempts yet

Problem

You are doing construction work, and to save money you bought discounted irregular blocks. Each irregular block is rectangular except for one edge, which is curvy. You wedge the irregular blocks between stacks of ordinary blocks so they cannot slide sideways or rotate. The lower irregular block sits with its curvy edge pointing up, and the one above it sits with its curvy edge pointing down. The upper block is lowered straight down until it just touches the lower one.

You want to know how well the two blocks fit together. At the moment the upper block just touches the lower one, the fit quality is the largest vertical gap between the upper edge of the bottom block and the lower edge of the top block.

Every block is one unit wide. Both curvy edges are cubic polynomials in xx, with the left edge of a block at x=0x = 0 and the right edge at x=1x = 1.

Input

The input holds several test cases and ends at end of file. There are at most 500 test cases.

Each test case is two lines, and each line holds four real numbers.

The first line gives b0b_0 b1b_1 b2b_2 b3b_3. The upper edge of the bottom block has the shape of b0+b1x+b2x2+b3x3b_0 + b_1 x + b_2 x^2 + b_3 x^3 for 0≤x≤10 \le x \le 1.

The second line gives t0t_0 t1t_1 t2t_2 t3t_3. The lower edge of the top block has the shape of t0+t1x+t2x2+t3x3t_0 + t_1 x + t_2 x^2 + t_3 x^3 for 0≤x≤10 \le x \le 1.

No input value has magnitude greater than 50000.

Output

For each test case, print the fit quality on its own line.

Round the value to six digits after the decimal point and always print all six digits, even when they are zero. A value of 3 prints as 3.000000.

No test case has an answer sitting on a boundary where the sixth digit could round either way.

Examples4

  1. Example 1

    Input
    1.000000 -12.904762 40.476190 -28.571429
    3.000000 11.607143 -34.424603 22.817460
    2.000000 -10.845238 16.964286 -10.119048
    3.000000 4.190476 -3.571429 2.380952
    
    Expected output
    4.396074
    6.999999
    
  2. Example 2

    Input
    1.500000 -2.250000 3.125000 -4.000000
    1.500000 -2.250000 3.125000 -4.000000
    0.000000 0.000000 0.000000 0.000000
    7.250000 0.000000 0.000000 0.000000
    
    Expected output
    0.000000
    0.000000
    
  3. Example 3

    Input
    0.000000 0.000000 0.000000 0.000000
    5.000000 -3.000000 0.000000 0.000000
    10.000000 4.000000 0.000000 0.000000
    10.000000 21.500000 0.000000 0.000000
    
    Expected output
    3.000000
    17.500000
    
  4. Example 4

    Input
    0.000000 0.000000 0.000000 0.000000
    0.000000 4.000000 -4.000000 0.000000
    0.000000 0.000000 0.000000 0.000000
    0.000000 10.000000 -2.000000 0.000000
    0.000000 0.000000 0.000000 0.000000
    0.000000 -9.000000 3.000000 0.000000
    
    Expected output
    1.000000
    8.000000
    6.000000