Under construction

Still being built. Things may change

Stacking Drums

Interview

Time limit1sMemory limit128 MB

Summary
Given bottom-row circle centers of drums stacked pyramid-style each resting on two below, compute the final top drum's center coordinates.
Level

Medium4 of 10

Topics
Geometry, Simulation, Math
Solved
No attempts yet

Problem

Drums of radius 1 are stacked inside a rectangular trash bin. The drums in the bottom row are held in place by the floor and walls, so they do not roll. Every drum above the bottom row touches two adjacent drums directly below it. Except for the top row, if a row contains k drums, the row immediately above it contains k-1 drums.

Given the x-coordinates of the centers of the drums in the bottom row, find the center coordinates of the drum at the very top after stacking all drums by this rule. Double precision floating point arithmetic is sufficient for all calculations.

Input

The first line contains the number of test cases T. T is at most 1000. Each test case is given on one line. The first value is N, the number of drums in the bottom row, followed by N numbers giving the x-coordinates of the centers of those drums. Since every bottom-row drum touches the floor, each of their center y-coordinates is 1.

N is between 1 and 10, inclusive. In the bottom row, the distance between the centers of two adjacent drums is at least 2.0 and at most 3.4. The lower bound 2.0 prevents drums from overlapping, and the upper bound 3.4 prevents unnecessary contact with a drum two rows above.

Output

For each test case, print one line containing the center coordinates of the top drum. Print the x-coordinate followed by the y-coordinate, separated by one space, with both values rounded to 4 digits after the decimal point.

Examples1

  1. Example 1

    Input
    5
    4 1.0 4.4 7.8 11.2
    1 1.0
    6 1.0 3.0 5.0 7.0 9.0 11.0
    10 1.0 3.0 5.0 7.0 9.0 11.0 13.0 15.0 17.0 20.4
    5 1.0 4.4 7.8 11.2 14.6
    
    Expected output
    6.1000 4.1607
    1.0000 1.0000
    6.0000 9.6603
    10.7000 15.9100
    7.8000 5.2143