Hide

Problem I
Lost Artwork

Your good friend Benjamin Gates believes he has found a map on the back of the Bill of Rights that leads to many famous paintings and other art pieces that were hidden during the Civil War in order to preserve them. He drags you into his hunt to find the location of this national treasure. The first part of what Ben claims to be a map, is a set of coordinates. You discover that these coordinates line up with the peaks and valleys of different parts of the Appalachian Mountains in Virginia. Upon further examination of the coordinates and the rest of the map, you and Ben begin to think that how the sunlight hits mountains as the sun sets is significant, and you draw the mapping shown below. In order to help Ben find the lost pieces of artwork, you’ve determined that you need to find the total lengths of each part of the mountain range hit by the sun at 5pm. These sections have been colored red on your map of a sample part of the mountain range. Write a program to determine the combined length of the colored sections of each part of the mountain range.

\includegraphics[width=0.5\textwidth ]{graph.png}
The sun is viewed as coming in from the right of the mountain at 5 PM. At 5 PM, the sun is shining from the right, infinitely far away so that the rays of light are effectively traveling horizontally.

Input

The first line contains a single integer $n$ ($1 \leq n \leq 1000$), the number of sections of the mountain range you will have to examine.

Each of the $n$ sections will start with a single integer $s$, ($s \leq 100$). The $s$ lines following each contain two space-separated integers x y, denoting an x and y coordinates of each point making the peaks and valleys of the mountain ($0 \leq x \leq 20000$, $0 \leq y \leq 8000$).

For the purposes of this problem, you can assume that the mountains will be non-overlapping, that the highest x value will have a y coordinate of 0 (at the foot of the mountain), and that the lowest x coordinate will always be at zero (the mountain range starts at x=0).

Output

A series of lengths (one per line) in which each length represents the length of a part of the mountain range that is hit by the sun at 5pm. Report each value with exactly two digits following the decimal.

Sample Input 1 Sample Output 1
2
11
1100 1200
0 500
1300 40
600 600
2200 0
200 1100
1300 200
1300 150
1400 300
1200 400
300 400
2
0 500
500 0
1764.41
707.11

Please log in to submit a solution to this problem

Log in