-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaximize it!.cpp
68 lines (52 loc) · 1.65 KB
/
Maximize it!.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <CGAL/QP_models.h>
#include <CGAL/QP_functions.h>
#include <CGAL/Gmpz.h>
using namespace std;
typedef int IT;
typedef CGAL::Gmpz ET;
typedef CGAL::Quadratic_program<IT> Program;
typedef CGAL::Quadratic_program_solution<ET> Solution;
const int X = 0;
const int Y = 1;
const int Z = 2;
int main() {
while (true) {
int p,a,b;
cin >> p >> a >> b;
if(p == 0) {
return 0;
}
if(p == 1) {
Program lp(CGAL::SMALLER, true, 0, false, 0);
lp.set_a(X,0,1); lp.set_a(Y,0,1); lp.set_b(0,4);
lp.set_a(X,1,4); lp.set_a(Y,1,2); lp.set_b(1,a*b);
lp.set_a(X,2,-1); lp.set_a(Y,2,1); lp.set_b (2,1);
lp.set_c(X,a); lp.set_c(Y,-b);
Solution s = CGAL::solve_linear_program(lp,ET());
if(s.is_infeasible()) {
cout << "no" << "\n";
} else if(s.is_unbounded()) {
cout << "unbounded" << "\n";
} else {
cout << floor(CGAL::to_double(-s.objective_value())) << endl;
}
}
if(p == 2) {
Program lp(CGAL::SMALLER, false, 0, true, 0);
lp.set_a(X,0,-1); lp.set_a(Y,0,-1); lp.set_a(Z,0,0);lp.set_b(0,4);
lp.set_a(X,1,-4); lp.set_a(Y,1,-2); lp.set_a(Z,1,-1);lp.set_b(1,a*b);
lp.set_a(X,2,1); lp.set_a(Y,2,-1); lp.set_a(Z,2,0);lp.set_b(2,1);
lp.set_c(X,a); lp.set_c(Y,b); lp.set_c(Z,1);
Solution s = CGAL::solve_linear_program(lp,ET());
if(s.is_infeasible()) {
cout << "no" << "\n";
} else if(s.is_unbounded()) {
cout << "unbounded" << "\n";
} else {
cout << ceil(CGAL::to_double(s.objective_value())) << endl;
}
}
}
return 0;
}