Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- using namespace std;
- void intersection(int* f1, int* f2, double& x, double& y) {
- double a = f1[0] * f2[1] - f2[0] * f1[1];
- x = (f2[2] * f1[1] - f1[2] * f2[1]) / a;
- y = (f2[0] * f1[2] - f1[0] * f2[2]) / a;
- }
- int main(void)
- {
- setlocale(LC_ALL, "Russian");
- int cel[3];
- int n;
- int mode;
- cout << "Введите номер варианта:" << endl << "1. Максимизировать (По умолчанию)" << endl << "2. Минимизировать" << endl;
- cin >> mode;
- if (mode != 1 && mode != 2) mode = 1;
- cout << "Введите количество уравнений:" << endl;
- cin >> n;
- int** arr = new int* [n];
- int* values = new int[n];
- for (int i = 0; i < n; ++i) arr[i] = new int[3];
- cout << "Уравнения должны иметь вид: ax1 + bx2 + c = 0" << endl;
- cout << "Введите целевую функцию по коэффициентам:" << endl;
- cout << "a:" << endl;
- cin >> cel[0];
- cout << "b:" << endl;
- cin >> cel[1];
- cout << "c:" << endl;
- cin >> cel[2];
- cout << "Вводите уравнения в системе по коэффициентам:" << endl;
- for (int i = 0; i < n; ++i) {
- cout << "Уравнение " << i + 1 << ":" << endl;
- cout << "a:" << endl;
- cin >> arr[i][0];
- cout << "b:" << endl;
- cin >> arr[i][1];
- cout << "c:" << endl;
- cin >> arr[i][2];
- cout << endl;
- }
- for (int i = 0; i < n; ++i) {
- double x, y;
- intersection(arr[i], arr[(i + 1) % n], x, y);
- cout << x << " " << y << endl;
- values[i] = x * cel[0] + y * cel[1] + cel[2];
- }
- if (mode == 1) {
- cout << "Максимальное значение: " << *max_element(values, values + n) << endl;
- }
- else {
- cout << "Минимальное значение: " << *min_element(values, values + n) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement