fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5. int main() {
  6. double h1, h2, l, d, a, b, r;
  7. cin >> d >> a >> b >> l;
  8. h1 = min(a,b);
  9. h2 = max(a,b);
  10. double res = h1;
  11. h1 = min (h1, (h2 - ((d*d - l*l)/(2*l))));
  12. if (h1 < 0) r = h2;
  13. else r = (sqrt(d*d + (h2-h1)*(h2-h1)));
  14. res += min(r, h2);
  15. cout << fixed << setprecision(5) << res;
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0.01s 5516KB
stdin
Standard input is empty
stdout
0.00000