fork download
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. // (0, ±e, d)
  6. // (±a, ±b, c)
  7. // (±b, ±a, -c)
  8. // (±e, 0, -d)
  9.  
  10. typedef double scalar;
  11.  
  12. scalar vol(scalar a, scalar b, scalar c, scalar d) {
  13. scalar e = (a * c - a * d + b * c + b * d) / (2 * c);
  14. if (!(0. <= e && e <= b)) {
  15. return 0.;
  16. }
  17. scalar h4 = hypot(a, d - c);
  18. scalar h53 = hypot(b - e, d - c);
  19. scalar h54 = hypot(a - b, 2 * c);
  20.  
  21. scalar s0 = ( (b + e) * h4 + a * h53 + (a + b) * h54 ) * 4.;
  22. scalar v0 = ( a * (d - c) * (b * 2. + e) + (a * a + b * b + 4 * a * b) * c ) * ((scalar)4. / (scalar)3.);
  23.  
  24. scalar s0_i = 1/s0;
  25. scalar r_s0_i = sqrt(s0_i);
  26. scalar v = v0 * r_s0_i * s0_i;
  27. return v;
  28. }
  29.  
  30. int main() {
  31. scalar v_max = 0.;
  32. scalar a_max = .5;
  33. scalar b_max = .5;
  34. scalar c_max = .5;
  35. scalar d_max = .5;
  36. scalar r = 1.;
  37. for (int i = 0; i < 53; i++) {
  38. for (int j = 0; j < 100; j++) {
  39. scalar a, b, c, d;
  40. do {
  41. a = a_max + (rand() * (1. / RAND_MAX) - .5) * r;
  42. b = b_max + (rand() * (1. / RAND_MAX) - .5) * r;
  43. c = c_max + (rand() * (1. / RAND_MAX) - .5) * r;
  44. d = d_max + (rand() * (1. / RAND_MAX) - .5) * r;
  45. } while (a <= b || c >= d);
  46. scalar v = vol(a, b, c, d);
  47. if (v > v_max) {
  48. v_max = v;
  49. a_max = a;
  50. b_max = b;
  51. c_max = c;
  52. d_max = d;
  53. }
  54. }
  55. r *= .5;
  56. }
  57. printf("%.16f\r\n", vol(a_max, b_max, c_max, d_max));
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 4512KB
stdin
Standard input is empty
stdout
0.0743448680932300