Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- const int n = 4;
- const int m = 3;
- int a[n][m] = {
- {7, 5, -40},
- {-5, 4, -6},
- {1, 2, -8},
- {0, 1, -4}
- };
- //Знаки =, >=, <= в уравнениях (1 -> >=) (0 -> =) (-1 -> <=)
- int b[n] = {-1, -1, 1, -1};
- double max(double a, double b) {
- return ((a > b) ? a : b);
- }
- double L(double x, double y) {
- return x + 2 * y;
- }
- bool intersection(int *f1, int *f2, double *x, double *y) {
- double a = f1[0] * f2[1] - f2[0] * f1[1];
- if (a == 0)
- return false;
- *x = (f2[2] * f1[1] - f1[2] * f2[1]) / a;
- *y = (f2[0] * f1[2] - f1[0] * f2[2]) / a;
- return true;
- }
- bool check_condition(double x, double y) {
- bool result = true;
- for (int i = 0; i < n; ++ i) {
- double v = a[i][0] * x + a[i][1] * y + a[i][2];
- if (b[i] == 0)
- result &= (v == 0);
- else
- result &= (v * b[i] >= 0);
- }
- return result;
- }
- int main(void) {
- bool iswrite = false;
- double mx, xmx, ymx;
- for (int i = 0; i < n; ++ i) {
- for (int j = 0; j < n; ++ j) {
- if (i == j) continue;
- double x, y;
- if (intersection(a[i], a[j], &x, &y) && check_condition(x, y)) {
- //printf("! %f %d %d\n", L(x, y), i, j);
- if (!iswrite) {
- mx = L(x, y);
- xmx = x;
- ymx = y;
- iswrite = true;
- }
- else {
- double f = L(x, y);
- if (f > mx) {
- mx = f;
- xmx = x;
- ymx = y;
- }
- }
- }
- }
- }
- printf("%f -> (%f, %f)\n", mx, xmx, ymx);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement