Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. using namespace std;
  2.  
  3. const double N = 5;
  4. const int n = 10;
  5. const int m = 10;
  6. const double EPS = 1e-9;
  7. const int u = 2;
  8. const int v = 2;
  9.  
  10.  
  11. double g_f(int i)
  12. {
  13. return 1.5 + sin(i + 1)/N;
  14. }
  15.  
  16. double h_f(int j)
  17. {
  18. return 1.5 + cos(j + 1)/N;
  19. }
  20.  
  21. vector<pair<double, int> > g, h;
  22.  
  23. double sum_g(double x)
  24. {
  25. int i = 0;
  26. while(i < m && g[i].first < x + EPS)
  27. i++;
  28.  
  29. return u*i;
  30. }
  31.  
  32. double sum_h(double x)
  33. {
  34. int j = n - 1;
  35. while(j >= 0 && h[j].first > x - EPS)
  36. j--;
  37.  
  38. return v*(n - j - 1);
  39. }
  40.  
  41. int main()
  42. {
  43. ofstream out("output.txt");
  44.  
  45. out << "N = " << N << "\n\n";
  46. out.precision(3);
  47. out << fixed;
  48.  
  49. for(int i = 0; i < m; i++)
  50. g.push_back({g_f(i), i});
  51. sort(g.begin(), g.end());
  52.  
  53. out << "i: \t";
  54. for(auto it: g)
  55. out << it.second << "\t ";
  56. out << "\ng: \t";
  57. for(auto it: g)
  58. out << it.first << "\t ";
  59. out << "\nsum g:\t";
  60. for(auto it: g)
  61. out << sum_g(it.first) << "\t ";
  62. out << "\n\n";
  63.  
  64.  
  65. for(int j = 0; j < n; j++)
  66. h.push_back({h_f(j), j});
  67. sort(h.begin(), h.end());
  68.  
  69. out << "j: \t";
  70. for(auto it: g)
  71. out << it.second << "\t ";
  72. out << "\nh: \t";
  73. for(auto it: h)
  74. out << it.first << "\t ";
  75. out << "\nsum h:\t";
  76. for(auto it: h)
  77. out << sum_h(it.first) << "\t ";
  78. //
  79. // vector <double> X;
  80. // for(int i = 0; i < m; i++)
  81. // X.push_back(g[i]);
  82. //
  83. // for(int j = 0; j < n; j++)
  84. // X.push_back(h[j]);
  85. // sort(X.begin(), X.end());
  86. //
  87. // double lam = -1;
  88. // double delta = 0;
  89. // for(auto x: X)
  90. // {
  91. // cout << sum_g(x) << " " << sum_h(x) << endl;
  92. // if(sum_g(x) >= sum_h(x))
  93. // {
  94. // lam = x;
  95. // delta = sum_g(x) - sum_h(x);
  96. // break;
  97. // }
  98. // }
  99. //
  100. // out << "lam: " << lam << endl;
  101. //
  102. // vector <double> x;
  103. // for(int i = 0; i < m; i++)
  104. // if(g[i] < lam + EPS)
  105. // x.push_back(u);
  106. // else
  107. // x.push_back(0);
  108. // out << "x:\t";
  109. // for(auto it: x)
  110. // out << it << "\t";
  111. // out << endl;
  112. //
  113. // vector <double> y;
  114. // for(int j = 0; j < m; j++)
  115. // if(h[j] < lam - EPS)
  116. // y.push_back(0);
  117. // else
  118. // y.push_back(v);
  119. // out << "y:\t";
  120. // for(auto it: y)
  121. // out << it << "\t";
  122.  
  123. // system("pause");
  124.  
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement