#P4986. Synchronised Exit

    ID: 18225 Type: Default 1000ms 256MiB

Synchronised Exit

Synchronised Exit

In a finite‐radius disc, two individuals start at the centre. They plan to leave the disc together in order to avoid an imbalance that would cause the entire space to collapse. Their methods differ:

  • Althen can change direction and is allowed only horizontal (to the right) and vertical (upward) moves. His average speed while moving rightwards is \(A(x)\) and upward is \(B(x)\).
  • hdxrie can only move in a straight line (cannot turn) with an average speed of \(C(x)\).

The parameter \(x\) (which may affect the speeds) is taken from an interval \([L, R]\). When both choose an exit point on the disc boundary, Althen must travel in two segments (first horizontally then vertically) while hdxrie goes straight from the centre to that exit. Since the disc is a circle (with finite radius \(r\)), if we assume the exit chosen is in the first quadrant then let the exit be \((u,v)\) with \(u,v \ge 0\) and \(u^2+v^2=r^2\).

The time taken by Althen is \(\frac{u}{A(x)} + \frac{v}{B(x)}\). Using an optimal path via Lagrange multipliers it can be shown that the minimum time for him is

\[ T_A = \frac{r\sqrt{A(x)^2+B(x)^2}}{A(x)\,B(x)}. \]

On the other hand, hdxrie's time is \(\frac{r}{C(x)}\). To leave together, they must have equal travel times, i.e.,

\[ \frac{r\sqrt{A(x)^2+B(x)^2}}{A(x)\,B(x)} = \frac{r}{C(x)}. \]

Simplifying (and noting \(r>0\)) leads to the equation

\[ A(x)\,B(x) - C(x)\sqrt{A(x)^2+B(x)^2} = 0. \]

You are given the interval \([L,R]\) and the definitions of \(A(x)\), \(B(x)\), \(C(x)\) as linear functions:

\[ A(x)=a\,x+b,\quad B(x)=c\,x+d,\quad C(x)=e\,x+f. \]

Your task is to determine whether there exists a parameter \(x\) in \([L, R]\) satisfying the above equation. If yes, output any such \(x\) (with an absolute error of at most \(10^{-6}\)); otherwise, output -1.

inputFormat

The input consists of 4 lines:

  1. The first line contains two space‐separated floating–point numbers \(L\) and \(R\) representing the interval for \(x\) (\(L < R\)).
  2. The second line contains two space–separated numbers \(a\) and \(b\) defining \(A(x)=a\,x+b\).
  3. The third line contains two space–separated numbers \(c\) and \(d\) defining \(B(x)=c\,x+d\).
  4. The fourth line contains two space–separated numbers \(e\) and \(f\) defining \(C(x)=e\,x+f\).

It is guaranteed that the speeds are positive for all \(x\) in \([L,R]\) and that the function

\[ f(x)=A(x)\,B(x) - C(x)\sqrt{A(x)^2+B(x)^2} \]

is continuous in \([L, R]\). You may assume that if a solution exists, it is unique.

outputFormat

Output a single floating–point number: a value \(x\) in \([L,R]\) that satisfies the equation with an absolute error of at most \(10^{-6}\). If no such \(x\) exists, output -1.

sample

-2 2
1 2
0 3
0 1
-0.939412