ICPC East Central NA Regional Contest 2016, Problem A
You may have seen a champagne tower at a wedding or an exclusive Hollywood A-list party. In a typical three-level tower, the first (lowest) level contains
Figure 1: Top-down view of a three-level champagne tower.
Champagne is always poured directly into the top glass. In this example, once the top glass fills and starts to overflow, it immediately begins filling the
The new fad is to make interesting patterns or imagery out of champagne glasses. These new-fangled "towers" needn't appear structurally sound; they can be held in place with complex support systems designed so as not to interfere with the overflowing champagne. Each of these new towers will always have a single highest glass into which all champagne is directly poured.
If two glass rims coincide vertically (i.e., have the same center and radius), then no accumulation occurs into the lower glass from the upper glass (though the overflowing champagne from the upper glass may still be collected by other lower glasses). Additionally, a single point of champagne overflow causes no measurable accumulation. In other words, measurable accumulation only occurs when a non-point arc of champagne overflows to the interior of a glass.
Your task is to determine whether a proposed champagne tower will fill to completion, and if so, how long it will take.
Input Specification
The input begins with a single integer
Output Specification
Display the number of seconds after which the tower will be completely filled, or Invalid
if the proposed champagne tower will never fill completely. Round answers to the hundredths place. Output values will always be
Sample Input 1
14
0 0 1 1 400
0 2 1 1 400
0 4 1 1 400
2 0 1 1 400
2 2 1 1 400
2 4 1 1 400
4 0 1 1 400
4 2 1 1 400
4 4 1 1 400
1 1 2 1 400
1 3 2 1 400
3 1 2 1 400
3 3 2 1 400
2 2 3 1 400
Sample Output 1
84.00
Sample Input 2
2
2 1 2 2 10
0 0 1 1 10
Sample Output 2
0.78
Sample Input 3
2
0 0 1 1 100
10 10 2 1 100
Sample Output 3
Invalid
Comments