-
Notifications
You must be signed in to change notification settings - Fork 9
/
inball.cpp
64 lines (50 loc) · 1.33 KB
/
inball.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
#include <iostream>
#include <CGAL/QP_models.h>
#include <CGAL/QP_functions.h>
#include <CGAL/Gmpz.h>
typedef int IT; // input type
typedef CGAL::Gmpz ET; // exact type for solver
typedef CGAL::Quadratic_program<IT> Program;
typedef CGAL::Quadratic_program_solution<ET> Solution;
using namespace std;
void solve(int n, int d) {
Program lp = Program(CGAL::SMALLER, false, 0, false, 0);
const int r = d;
// a.dot(c) + ||a||r <= b
int aij, bi, norm;
for (int i = 0; i < n; ++i) {
norm = 0;
for (int j = 0; j < d; ++j) {
cin >> aij;
norm += aij * aij;
lp.set_a(j, i, aij);
}
norm = sqrt(norm);
lp.set_a(r, i, norm);
cin >> bi;
lp.set_b(i, bi);
}
// Radius needs to be positive
lp.set_l(r, true, 0);
// Maximize radius
lp.set_c(r, -1);
Solution s = CGAL::solve_linear_program(lp, ET());
if (s.is_infeasible()) {
cout << "none" << endl;
}
else if (s.is_unbounded()) {
cout << "inf" << endl;
}
else {
// Implicit round down due to integer division
cout << - s.objective_value_numerator() / s.objective_value_denominator() << endl;
}
}
int main() {
int n, d;
while (cin >> n && n > 0) {
cin >> d;
solve(n, d);
}
return 0;
}