fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. const double pi = 4.0 * atan(1.0);
  7.  
  8. double S(double a, double b, double x)
  9. {
  10. return pi * b * x / (2 * sqrt(1 - a * a / (4 * x * x)));
  11. }
  12.  
  13. double solve(double a, double b)
  14. {
  15. const double eps = 1e-9;
  16. double l = a / 2;
  17. double u = a;
  18.  
  19. while (u - l > eps) {
  20. double m1 = l + 1 * (u - l) / 3;
  21. double m2 = l + 2 * (u - l) / 3;
  22. double f1 = S(a, b, m1);
  23. double f2 = S(a, b, m2);
  24. if (f1 < f2) {
  25. u = m2;
  26. } else {
  27. l = m1;
  28. }
  29. }
  30. return S(a, b, (l + u) / 2);
  31. }
  32.  
  33. int main()
  34. {
  35. double a, b;
  36. while (cin >> a >> b) {
  37. cout << solve(a, b) << endl;
  38. }
  39. }
  40.  
Success #stdin #stdout 0s 3432KB
stdin
31.0 2.0
28.0 5.0
stdout
97.3894
219.911