#include #define rep(i,a,b) for(int i=a;i double findMinReal(double L, double R, Func f) { //[L, R) double left = L, right = R; for (int loop = 0; loop < 101010; ++loop) { if (f((left * 2 + right) / 3) <= f((left + right * 2) / 3)) { right = (left + right * 2) / 3; } else { left = (left * 2 + right) / 3; } } return (right + left) * 0.5; } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  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, 1e4, f); printf("%.10f\n", p); }