Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Cross Points of Circles

For given two circles $c1$ and $c2$, print the coordinates of the cross points of them.

Input

The input is given in the following format.

$c1x\; c1y\; c1r$

$c2x\; c2y\; c2r$

$c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle.
$c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle.
All input values are given in integers.

Output

Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules.

If there is one cross point, print two coordinates with the same values.

Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first.

The output values should be in a decimal fraction with an error less than 0.000001.

Constraints

The given circle have at least one cross point and have different center coordinates.

$-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$

$1 \leq c1r, c2r \leq 10,000$

Sample Input and Output

Sample Input 1

0 0 2
2 0 2

Sample Output 1

1.00000000 -1.73205080 1.00000000 1.73205080

Sample Input 2

0 0 2
0 3 1

Sample Output 2

0.00000000 2.00000000 0.00000000 2.00000000

Solution in Ruby (judge verdict: Accepted)

module Geometry
  EPS = 1e-11
  COUNTER_CLOCKWISE = 1
  CLOCKWISE = -1
  ONLINE_BACK = 2
  ONLINE_FRONT = -2
  ON_SEGMENT = 0

  Point = Struct.new(:y, :x) do
    def +(point)
      Point.new(y + point.y, x + point.x)
    end

    def -(point)
      Point.new(y - point.y, x - point.x)
    end
  end

  Circle = Struct.new(:c, :r)
  Line = Struct.new(:p1, :p2)

  def norm(v)
    v.x ** 2 + v.y ** 2
  end

  def abs(v)
    Math.sqrt(norm(v))
  end

  def dot(v1, v2)
    v1.x * v2.x + v1.y * v2.y
  end

  def cross(v1, v2)
    v1.x * v2.y - v1.y * v2.x
  end

  def arg(v)
    Math.atan2(v.y, v.x)
  end

  def polar(a, r)
    Point.new(Math.sin(r) * a, Math.cos(r) * a)
  end

  def ccw(p0, p1, p2)
    a = p1 - p0
    b = p2 - p0

    return COUNTER_CLOCKWISE if cross(a, b) > EPS
    return CLOCKWISE if cross(a, b) < -EPS
    return ONLINE_BACK if dot(a, b) < -EPS
    return ONLINE_FRONT if norm(a) < norm(b)

    ON_SEGMENT
  end

  def intersect(p1, p2, p3, p4)
    ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0
  end

  def get_circle_cross_point(c1, c2)
    d = abs(c1.c - c2.c)
    a = Math.acos(Rational(c1.r ** 2 + d ** 2 - c2.r ** 2, 2 * c1.r * d))
    t = arg(c2.c - c1.c)
    [c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)]
  end
end

include Geometry

c1x, c1y, c1r = gets.split.map(&:to_i)
c2x, c2y, c2r = gets.split.map(&:to_i)

c1 = Circle.new(Point.new(c1y, c1x), c1r)
c2 = Circle.new(Point.new(c2y, c2x), c2r)

p1, p2 = get_circle_cross_point(c1, c2)

list = [[p1.x, p1.y], [p2.x, p2.y]].sort_by { |a, b| [a, b] }.flatten

puts "%.8f %.8f %.8f %.8f" % list