fork download
  1. #include <iostream>
  2. #include <random>
  3. #include <cmath>
  4. #include <limits>
  5. #include <ctime>
  6.  
  7. const std::string currentDateTime() {
  8. time_t now = time(0);
  9. struct tm tstruct;
  10. char buf[80];
  11. tstruct = *localtime(&now);
  12. strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
  13.  
  14. return buf;
  15. }
  16.  
  17. int main()
  18. {
  19. typedef std::numeric_limits< double > dbl;
  20.  
  21. std::default_random_engine generator;
  22. std::normal_distribution<double> distribution(0.0, 1.0);
  23.  
  24. std::cout.precision(dbl::digits10);
  25.  
  26. const long long N=1390737600000;
  27. long long i, in;
  28.  
  29. double x, y, xz1, yz1, diff;
  30. xz1 = 0.0;
  31. yz1 = 0.0;
  32. diff = 0.0;
  33.  
  34. x = distribution(generator);
  35. y = 0.5*yz1 + x - 0.5*xz1;
  36. diff = std::abs(x-y);
  37.  
  38. in = 1L;
  39. for (i=0; i<N; i++){
  40. x = distribution(generator);
  41. y = 0.5*yz1 + x - 0.5*xz1;
  42. diff = diff > std::abs(x-y) ? diff : std::abs(x-y);
  43. xz1 = x;
  44. yz1 = y;
  45.  
  46. if (i == in) {
  47. std::cout << "[" << currentDateTime() << "] -- " << std::scientific << diff << " [" << in << "] " << std::endl;
  48. in *= 10;
  49. }
  50. }
  51.  
  52. std::cout.precision(dbl::digits10);
  53. std::cout << "Maximum difference is: " << std::scientific << diff << std::endl;
  54.  
  55. return 0;
  56. }
  57.  
  58. /* Output:
  59.  
  60. [2015-02-25.15:00:56] -- 0.000000000000000e+00 [1]
  61. [2015-02-25.15:00:56] -- 1.387778780781446e-17 [10]
  62. [2015-02-25.15:00:56] -- 4.440892098500626e-16 [100]
  63. [2015-02-25.15:00:56] -- 4.440892098500626e-16 [1000]
  64. [2015-02-25.15:00:56] -- 4.440892098500626e-16 [10000]
  65. [2015-02-25.15:00:56] -- 4.440892098500626e-16 [100000]
  66. [2015-02-25.15:00:56] -- 8.881784197001252e-16 [1000000]
  67. [2015-02-25.15:00:58] -- 8.881784197001252e-16 [10000000]
  68. [2015-02-25.15:01:18] -- 8.881784197001252e-16 [100000000]
  69. [2015-02-25.15:04:36] -- 8.881784197001252e-16 [1000000000]
  70. [2015-02-25.15:37:35] -- 8.881784197001252e-16 [10000000000]
  71. [2015-02-25.21:13:03] -- 8.881784197001252e-16 [100000000000]
  72. [2015-02-28.05:09:45] -- 8.881784197001252e-16 [1000000000000]
  73. Maximum difference is: 8.881784197001252e-16
  74.  
  75. */
  76.  
Time limit exceeded #stdin #stdout 5s 3232KB
stdin
Standard input is empty
stdout
[2015-03-02.06:31:10] -- 0.000000000000000e+00  [1] 
[2015-03-02.06:31:10] -- 2.032879073410321e-20  [10] 
[2015-03-02.06:31:10] -- 2.710505431213761e-20  [100] 
[2015-03-02.06:31:10] -- 1.084202172485504e-19  [1000] 
[2015-03-02.06:31:10] -- 1.110223024625157e-16  [10000] 
[2015-03-02.06:31:10] -- 1.110223024625157e-16  [100000] 
[2015-03-02.06:31:10] -- 1.110765125711399e-16  [1000000] 
[2015-03-02.06:31:11] -- 2.220446049250313e-16  [10000000]