|
<p> |
|
Come one, come all! The most famous circus troupe in all the land is on tour! |
|
Having just arrived in a new location, they're eager to set up their big top and showcase world-class acts of acrobatics and comedy |
|
for their audience. |
|
</p> |
|
|
|
<p> |
|
Looking at the tent from the side (as a cross section), it will be set up along a one-dimensional strip of ground. |
|
<strong>N</strong> vertical poles will be placed in the ground, one after another, |
|
with the <em>i</em>th pole at a position <strong>X<sub>i</sub></strong> meters to the right of an arbitrary reference point, |
|
and reaching a height of <strong>H<sub>i</sub></strong> meters. No two poles will be at the same position. |
|
</p> |
|
|
|
<p> |
|
After each pole is placed, the shape of the tent will be updated to fit the current set of poles. |
|
In particular, the upper outline of the tent will be a function with the following properties: |
|
|
|
<ol> |
|
<li> it's defined over all positions from negative infinity to positive infinity </li> |
|
|
|
<li> its height is always non-negative </li> |
|
|
|
<li> it's made up entirely of a series of connected line segments, with each one having a slope with absolute value no greater than 1 |
|
(meaning that the function is continuous, and its height may never change from left to right at an angle of more than 45 degrees up/down) |
|
</li> |
|
|
|
<li> it doesn't intersect with any of the poles (meaning that, at each pole's position, |
|
the function's height must be no smaller than that of the pole) </li> |
|
</ol> |
|
</p> |
|
|
|
<p> |
|
The cross-sectional area of the tent is the area under this function. |
|
Despite their popularity, the circus troupe doesn't exactly have money to spare on tent materials |
|
(with most of their budget allocated to feeding their flying elephant star). |
|
As such, they'd like to minimize the cross-sectional area of their tent after placing each of the <strong>N</strong> poles. |
|
They'd like you to calculate the sum of these <strong>N</strong> minimal areas for them. |
|
</p> |
|
|
|
<p> |
|
In this example, three poles are placed one after another. The first is at X = 20 with height 10. The minimum area of the tent is 100 m<sup>2</sup>. |
|
The second pole is placed at X = 30 with a height of 15. The minimum area of the tent is now 268.75 m<sup>2</sup>. The third pole is at X = 24 with a height of 3. This doesn't change the minimum area of the tent, which is still 268.75 m<sup>2</sup>. |
|
</p> |
|
|
|
<img src="{{PHOTO_ID:1437352136460846}}" /> |
|
<img src="{{PHOTO_ID:1162015730825186}}" /> |
|
<img src="{{PHOTO_ID:262229418531119}}" /> |
|
|
|
<p> |
|
You're given <strong>X<sub>1</sub></strong>, and <strong>X<sub>2..N</sub></strong> may then be calculated as follows, |
|
using given constants <strong>A<sub>x</sub></strong>, <strong>B<sub>x</sub></strong>, and <strong>C<sub>x</sub></strong> |
|
(note that it is guaranteed that <strong>X<sub>1..N</sub></strong> will be distinct): |
|
</p> |
|
|
|
<p> |
|
<strong>X<sub>i</sub></strong> = |
|
((<strong>A<sub>x</sub></strong> * <strong>X<sub>i-1</sub></strong> + <strong>B<sub>x</sub></strong>) % |
|
<strong>C<sub>x</sub></strong>) + 1 |
|
</p> |
|
|
|
<p> |
|
Similarly, you're given <strong>H<sub>1</sub></strong>, and <strong>H<sub>2..N</sub></strong> may then be calculated as follows, |
|
using given constants <strong>A<sub>h</sub></strong>, <strong>B<sub>h</sub></strong>, and <strong>C<sub>h</sub></strong>: |
|
</p> |
|
|
|
<p> |
|
<strong>H<sub>i</sub></strong> = |
|
((<strong>A<sub>h</sub></strong> * <strong>H<sub>i-1</sub></strong> + <strong>B<sub>h</sub></strong>) % |
|
<strong>C<sub>h</sub></strong>) + 1 |
|
</p> |
|
|
|
|
|
<h3>Input</h3> |
|
|
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of different tents that the circus troupe will set up. |
|
For each tent, there is first a line containing the single integer <strong>N</strong>. |
|
Then there is a line containing the four space-separated integers |
|
<strong>X<sub>1</sub></strong>, <strong>A<sub>x</sub></strong>, |
|
<strong>B<sub>x</sub></strong>, and <strong>C<sub>x</sub></strong>. |
|
Then there is a line containing the four space-separated integers |
|
<strong>H<sub>1</sub></strong>, <strong>A<sub>h</sub></strong>, |
|
<strong>B<sub>h</sub></strong>, and <strong>C<sub>h</sub></strong>. |
|
</p> |
|
|
|
<h3>Output</h3> |
|
|
|
<p> |
|
For the <em>i</em>th tent, print a line containing "Case #<strong>i</strong>: " followed by one real number. |
|
This number is the sum of <strong>N</strong> values, the <em>j</em>th of which is the minimum possible cross-sectional area |
|
of the tent after poles 1 through <em>j</em> have been placed. |
|
</p> |
|
|
|
<p> |
|
Answers that have a relative error of up to 10<sup>-6</sup> will be accepted as correct. |
|
</p> |
|
|
|
<h3>Constraints</h3> |
|
|
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 150 <br /> |
|
1 ≤ <strong>N</strong> ≤ 800,000 <br /> |
|
1 ≤ <strong>X<sub>1</sub></strong> ≤ 10,000,000 <br /> |
|
0 ≤ <strong>A<sub>x</sub></strong>, <strong>B<sub>x</sub></strong> ≤ 10,000,000 <br /> |
|
1 ≤ <strong>C<sub>x</sub></strong> ≤ 10,000,000 <br /> |
|
1 ≤ <strong>H<sub>1</sub></strong> ≤ 100,000 <br /> |
|
0 ≤ <strong>A<sub>h</sub></strong>, <strong>B<sub>h</sub></strong> ≤ 100,000 <br /> |
|
1 ≤ <strong>C<sub>h</sub></strong> ≤ 100,000 <br /> |
|
</p> |
|
|
|
<h3>Explanation of Sample</h3> |
|
|
|
<p> |
|
In the first case, the cross-sectional areas of the tent after each pole is erected are 1.0, 1.75, 2.5, 3.25, and 4.0 for a total of 12.50. |
|
</p> |
|
|