fork(31) download
  1.  
  2.  
  3. #include <iostream>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. double up = 19.0 + (61.0/125.0);
  9. double down = -32.0 - (2.0/3.0);
  10. double rectangle = (up - down) * 8.0;
  11.  
  12. double f(double x) {
  13. return (pow(x, 4.0)/500.0) - (pow(x, 2.0)/200.0) - 0.012;
  14. }
  15.  
  16. double g(double x) {
  17. return -(pow(x, 3.0)/30.0) + (x/20.0) + (1.0/6.0);
  18. }
  19.  
  20. double area_upper(double x, double step) {
  21. return (((up - f(x)) + (up - f(x + step))) * step) / 2.0;
  22. }
  23.  
  24. double area_lower(double x, double step) {
  25. return (((g(x) - down) + (g(x + step) - down)) * step) / 2.0;
  26. }
  27.  
  28. double area(double x, double step) {
  29. return area_upper(x, step) + area_lower(x, step);
  30. }
  31.  
  32. int main() {
  33. double current = 0, last = 0, step = 1.0;
  34.  
  35. do {
  36. last = current;
  37. step /= 10.0;
  38. current = 0;
  39.  
  40. for(double x = 2.0; x < 10.0; x += step) current += area(x, step);
  41.  
  42. current = rectangle - current;
  43. current = round(current * 1000.0) / 1000.0;
  44. //cout << current << endl; //<-- COMMENT BACK IN TO "FIX" BUG
  45. } while(current != last);
  46.  
  47. cout << current << endl;
  48. return 0;
  49. }
  50.  
Time limit exceeded #stdin #stdout 5s 3136KB
stdin
Standard input is empty
stdout
Standard output is empty