This page is still under construction.

Parts of this page are still being built. What you see may change.

Venn Diagram

Time limit8sMemory limit512 MB

Summary
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 AA and BB.

A Venn diagram shows how sets relate to one another. In a Venn diagram of AA and BB, the outer rectangle is the universal set UU, and the two circles inside it are AA and BB. The region where the circles overlap corresponds to the intersection A∩BA \cap B.

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 ∣A∣|A|, the other has area ∣B∣|B|, and the overlap of the two circles has area ∣A∩B∣|A \cap B|. Here ∣X∣|X| is the number of elements of a set XX.

The rectangle is already drawn. Its lower left corner is (0,0)(0, 0) and its upper right corner is (UW,UH)(U_W, U_H). 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 300300 of them. Each dataset is one line with five integers.

UW UH |A| |B| |A∩B|

UWU_W and UHU_H (1≤UW,UH≤1001 \le U_W, U_H \le 100) are the width and the height of the rectangle that stands for the universal set UU. ∣A∣|A|, ∣B∣|B| and ∣A∩B∣|A \cap B| (1≤∣A∣,∣B∣≤100001 \le |A|, |B| \le 10000, 0≤∣A∩B∣≤min⁡(∣A∣,∣B∣)0 \le |A \cap B| \le \min(|A|, |B|)) are the numbers of elements of AA, BB and A∩BA \cap B. The last line holds five zeroes and is not a dataset.

Whether the two circles can be drawn does not change when UWU_W and UHU_H move by up to 0.010.01 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: RA=∣A∣/πR_A = \sqrt{|A| / \pi} and RB=∣B∣/πR_B = \sqrt{|B| / \pi}.

Let dd be the smallest distance between the two centres at which the overlap area equals ∣A∩B∣|A \cap B|. If ∣A∩B∣=0|A \cap B| = 0, then d=RA+RBd = R_A + R_B. If ∣A∩B∣=min⁡(∣A∣,∣B∣)|A \cap B| = \min(|A|, |B|), then d=0d = 0. Otherwise exactly one dd with ∣RA−RB∣<d<RA+RB|R_A - R_B| < d < R_A + R_B gives that overlap area.

The two circles can be drawn exactly when both of the following hold.

  • 2max⁡(RA,RB)≤min⁡(UW,UH)2\max(R_A, R_B) \le \min(U_W, U_H)
  • d≤Dd \le D, where D=(UW−RA−RB)2+(UH−RA−RB)2D = \sqrt{(U_W - R_A - R_B)^2 + (U_H - R_A - R_B)^2}

If either one fails, print impossible.

Otherwise let s=d/Ds = d / D, and let s=0s = 0 when D=0D = 0. Print the six values

  • XA=UW/2−s(UW/2−RA)X_A = U_W/2 - s (U_W/2 - R_A)
  • YA=UH/2−s(UH/2−RA)Y_A = U_H/2 - s (U_H/2 - R_A)
  • RAR_A
  • XB=UW/2+s(UW/2−RB)X_B = U_W/2 + s (U_W/2 - R_B)
  • YB=UH/2+s(UH/2−RB)Y_B = U_H/2 + s (U_H/2 - R_B)
  • RBR_B

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 AA lies on the segment from the centre of the rectangle to the point (RA,RA)(R_A, R_A), the centre of circle BB lies on the segment from the centre of the rectangle to the point (UW−RB,UH−RB)(U_W - R_B, U_H - R_B), and both centres sit the same fraction ss of the way along their own segment.

Examples1

  1. Example 1

    Input
    10 5 1 1 0
    10 5 2 2 1
    10 10 70 70 20
    0 0 0 0 0
    
    Expected output
    4.482905895 2.274337480 0.564189584 5.517094105 2.725662520 0.564189584
    4.701254289 2.378989596 0.797884561 5.298745711 2.621010404 0.797884561
    impossible