Welcome to ZOJ
Select Problem
ZOJ Problem Set - 2519
Cutting a Cake

Time Limit: 2 Seconds      Memory Limit: 65536 KB

You are going to receive a big big birthday cake from the Algorithm City of Mathematics (ACM). The rectangle cake is so big that everyone in the city can come to share a piece with you. But first, as the birthday boy/girl, you have to pass a test.

You are standing at the center of the city square, and are given a magic knife that can be stretched as long as you like. The cake is placed in front of you and the four sides of it are parallel to either the West-East or the South-North axes. Given two positive integers a and b, you are supposed to cut the cake into two pieces so that the cakes to your left-hand-side and that to your right-hand-side are in the proportion of a:b.

Figure 1 shows a way to cut the cake into 1:1, and Figure 2 illustrates how to cut it into 1:2.

The input consists of several test cases, each occupies a line with 6 integers: x1, y1, x2, y2, a and b, where (x1, y1) and (x2, y2) are the coordinates of the lower-left and upper-right corners of the rectangle cake, a and b are described in the problem. It is guaranteed that you will not be standing on the top of the cake or at any corner of the cake.

For each test case, output in a line the slope of your knife to cut the cake in the proportion of a:b. Your answer must be accurate up to 2 decimal places. If the knife must be parallel to the y-axis, output "Infinity" instead.

Sample Input:
1 1 3 3 1 1
-2 -3 1 -1 1 2
Sample Output:

Author: CHEN, Yue
Source: CYJJ's Funny Contest #2, Relaxing on Math
Submit    Status