Venn Diagram
Time limit8sMemory limit512 MB
Place two circles with given areas and overlap inside a rectangle, or report that the placement is impossible.
- Level
Medium7 of 10
- Topics
- Geometry, Binary search, Math
- Solved
- No attempts yet
Problem
Alice teaches privately, and preparing the material is part of her job. Right now she is drawing a Venn diagram of two sets and .
A Venn diagram shows how sets relate to one another. In a Venn diagram of and , the outer rectangle is the universal set , and the two circles inside it are and . The region where the circles overlap corresponds to the intersection .
Alice wants the picture to carry the numbers too, so she imposed a condition: the area of every region must equal the number of elements of the set that region stands for. One circle has area , the other has area , and the overlap of the two circles has area . Here is the number of elements of a set .
The rectangle is already drawn. Its lower left corner is and its upper right corner is . Both circles have to lie inside that rectangle. Write a program that computes the centre and the radius of each circle.
Input
The input holds several datasets. There are at most of them. Each dataset is one line with five integers.
UW UH |A| |B| |A∩B|
and () are the width and the height of the rectangle that stands for the universal set . , and (, ) are the numbers of elements of , and . The last line holds five zeroes and is not a dataset.
Whether the two circles can be drawn does not change when and move by up to in either direction.
Output
Print one line for each dataset. Many placements satisfy Alice's condition, so print the single placement that the rule below picks out.
The radii follow from the areas: and .
Let be the smallest distance between the two centres at which the overlap area equals . If , then . If , then . Otherwise exactly one with gives that overlap area.
The two circles can be drawn exactly when both of the following hold.
- , where
If either one fails, print impossible.
Otherwise let , and let when . Print the six values
in that order, on one line, separated by single spaces, each with exactly nine digits after the decimal point. In words: the centre of circle lies on the segment from the centre of the rectangle to the point , the centre of circle lies on the segment from the centre of the rectangle to the point , and both centres sit the same fraction of the way along their own segment.