#include #include double pyt(double sa, double sb) { return ::sqrt((sa * sa) + (sb * sb)); } double f(double ax, double ay, double bx, double by) { if (ay == by) { return ay; } double p_min = ay < by? ay: by; double p_len = ::fabs(ay - by); double p_max = p_min + p_len; double n = 0; double rc = ax; double wk = pyt(ax, p_len) + bx; while (n <= p_len) { double a = pyt(ax, (ay < by? n: (p_len - n))); double b = pyt(bx, (by < ay? n: (p_len - n))); double w = a + b; if (w < wk) { wk = w; rc = n; } n += 0.001; } return p_min + rc; } int main() { double ax, ay, bx, by; std::cin >> ax; std::cin >> ay; std::cin >> bx; std::cin >> by; std::cout << f(ax, ay, bx, by) << std::endl; return 0; }