Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- const double N = 5;
- const int n = 10;
- const int m = 10;
- const double EPS = 1e-9;
- const int u = 2;
- const int v = 2;
- double g_f(int i)
- {
- return 1.5 + sin(i + 1)/N;
- }
- double h_f(int j)
- {
- return 1.5 + cos(j + 1)/N;
- }
- vector<pair<double, int> > g, h;
- double sum_g(double x)
- {
- int i = 0;
- while(i < m && g[i].first < x + EPS)
- i++;
- return u*i;
- }
- double sum_h(double x)
- {
- int j = n - 1;
- while(j >= 0 && h[j].first > x - EPS)
- j--;
- return v*(n - j - 1);
- }
- int main()
- {
- ofstream out("output.txt");
- out << "N = " << N << "\n\n";
- out.precision(3);
- out << fixed;
- for(int i = 0; i < m; i++)
- g.push_back({g_f(i), i});
- sort(g.begin(), g.end());
- out << "i: \t";
- for(auto it: g)
- out << it.second << "\t ";
- out << "\ng: \t";
- for(auto it: g)
- out << it.first << "\t ";
- out << "\nsum g:\t";
- for(auto it: g)
- out << sum_g(it.first) << "\t ";
- out << "\n\n";
- for(int j = 0; j < n; j++)
- h.push_back({h_f(j), j});
- sort(h.begin(), h.end());
- out << "j: \t";
- for(auto it: g)
- out << it.second << "\t ";
- out << "\nh: \t";
- for(auto it: h)
- out << it.first << "\t ";
- out << "\nsum h:\t";
- for(auto it: h)
- out << sum_h(it.first) << "\t ";
- //
- // vector <double> X;
- // for(int i = 0; i < m; i++)
- // X.push_back(g[i]);
- //
- // for(int j = 0; j < n; j++)
- // X.push_back(h[j]);
- // sort(X.begin(), X.end());
- //
- // double lam = -1;
- // double delta = 0;
- // for(auto x: X)
- // {
- // cout << sum_g(x) << " " << sum_h(x) << endl;
- // if(sum_g(x) >= sum_h(x))
- // {
- // lam = x;
- // delta = sum_g(x) - sum_h(x);
- // break;
- // }
- // }
- //
- // out << "lam: " << lam << endl;
- //
- // vector <double> x;
- // for(int i = 0; i < m; i++)
- // if(g[i] < lam + EPS)
- // x.push_back(u);
- // else
- // x.push_back(0);
- // out << "x:\t";
- // for(auto it: x)
- // out << it << "\t";
- // out << endl;
- //
- // vector <double> y;
- // for(int j = 0; j < m; j++)
- // if(h[j] < lam - EPS)
- // y.push_back(0);
- // else
- // y.push_back(v);
- // out << "y:\t";
- // for(auto it: y)
- // out << it << "\t";
- // system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement