Advertisement
Tetriss

Untitled

Feb 12th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. struct Func
  9. {
  10. double x;
  11. double y;
  12. };
  13.  
  14. double function1(const double& x)
  15. {
  16. double y;
  17. y = cos(x)+log10(x);
  18. return y;
  19. }
  20. double function2(const double& x)
  21. {
  22. double y;
  23. y = (cos(x)+log10(x)) * sin(5 * x);
  24. return y;
  25. }
  26. int Round(const double& N)
  27. {
  28. int n;
  29. if ((int)N < N) n = N + 1;
  30. else n = (int)N;
  31. return n;
  32. }
  33. double Rand(double Min, double Max)
  34. {
  35. double f = (double)rand() / RAND_MAX;
  36. return Min + f * (Max - Min);
  37. }
  38.  
  39.  
  40. int main()
  41. {
  42. double a = 7, b = 10;
  43. double N;
  44. vector <Func> functions;
  45. cout << " q/P 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99" << endl << endl;
  46. for (double q = 0.005; q < 0.105; q = q + 0.005)
  47. {
  48. cout << right << setw(6) << q << " ";
  49. for (double P = 0.9; P < 1; P = P + 0.01)
  50. {
  51. N = (log(1 - P)) / (log(1 - q));
  52. cout << right << setw(6) << Round(N) << " ";
  53. }
  54. cout << endl;
  55. }
  56.  
  57. cout << endl << endl;
  58. cout << " q/P 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99" << endl << endl;
  59.  
  60. for (double q = 0.005; q < 0.105; q = q + 0.005)
  61. {
  62. cout << right << setw(6) << q << " ";
  63. for (double P = 0.9; P < 1; P = P + 0.01)
  64. {
  65. N = (log(1 - P)) / (log(1 - q));
  66. functions.resize(Round(N));
  67. for (auto i = 0; i < Round(N); i++)
  68. {
  69. functions[i].x = Rand(a, b);
  70. functions[i].y = function1(functions[i].x);
  71. }
  72. sort(begin(functions), end(functions), [](auto a, auto b) { return a.y < b.y; });
  73. cout << right << setw(8) << functions[0].y << " ";
  74. }
  75. cout << endl;
  76. }
  77.  
  78. cout << endl << endl;
  79. cout << " q/P 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99" << endl << endl;
  80.  
  81. for (double q = 0.005; q < 0.105; q = q + 0.005)
  82. {
  83. cout << right << setw(6) << q << " ";
  84. for (double P = 0.9; P < 1; P = P + 0.01)
  85. {
  86. N = (log(1 - P)) / (log(1 - q));
  87. functions.resize(Round(N));
  88. for (auto i = 0; i < Round(N); i++)
  89. {
  90. functions[i].x = Rand(a, b);
  91. functions[i].y = function2(functions[i].x);
  92. }
  93. sort(begin(functions), end(functions), [](auto a, auto b) { return a.y < b.y; });
  94. cout << right << setw(9) << functions[0].y << " ";
  95. }
  96. cout << endl;
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement