Random Walk
Time limit1sMemory limit128 MB
Given n nonparallel 2D vectors, choose a sign for each so the resulting sum has maximum Euclidean length.
Problem
Random walks model many phenomena, from Brownian motion to gambling. For example, a gambler who bets on heads or tails on each coin toss wins or loses the bet every turn, and the amount of money the gambler holds over time is a random walk. Although the bet may differ each turn, it is easy to see that the gambler ends with the most money by winning every turn, and with the least money by losing every turn.
We study the following two-dimensional variant. You are given nonzero two-dimensional vectors , no two of which are parallel. In step a coin is flipped: on heads you move meters in the direction and meters in the direction; on tails you move and meters instead. After all steps the displacement from the origin is , where each .
Compute the maximum possible distance from the starting point, that is . This is easy in one dimension, but not so easy in two.
Input
The input consists of several test cases. Each test case begins with a line containing the integer (). Each of the next lines contains two integers and describing ; each coordinate is less than in magnitude. A line containing marks the end of the input and is not processed.
Output
For each test case, print one line in exactly this format:
Maximum distance = D.DDD meters.
where D.DDD is the maximum distance from the starting point, rounded to exactly three decimal places.