#include #define rep(i,a,b) for(int i=a;i double findMinReal(double L, double R, Func f) { //[L, R) double l = L, r = R; rep(i, 0, 1010) { double m1 = (l * 2.0 + r) / 3.0; double m2 = (l + r * 2.0) / 3.0; if (f(m1) > f(m2)) l = m1; else r = m2; } return r; } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ double a, b, c, d; //--------------------------------------------------------------------------------------------------- double f(double x) { double d1 = sqrt(a * a + (b - x) * (b - x)); double d2 = sqrt(c * c + (d - x) * (d - x)); return d1 + d2; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> a >> b >> c >> d; double p = findMinReal(0, 1e9, f); printf("%.10f\n", p); }