Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <numeric>
- #include <limits>
- #include <stdexcept>
- // example: how to solve a simple explicit LP
- #include <CGAL/QP_models.h>
- #include <CGAL/QP_functions.h>
- #include <CGAL/Gmpq.h>
- // choose input type (input coefficients must fit)
- typedef CGAL::Gmpq IT;
- // choose exact type for solver (CGAL::Gmpz or CGAL::Gmpq)
- typedef CGAL::Gmpq ET;
- // program and solution types
- typedef CGAL::Quadratic_program<IT> Program;
- typedef CGAL::Quadratic_program_solution<ET> Solution;
- using namespace std;
- void testcase()
- {
- int n, m, h, w;
- cin >> n >> m >> h >> w;
- vector<pair<int, int>> variables;
- vector<pair<int, int>> constants;
- for (int i = 0; i < n; i++)
- {
- int x, y;
- cin >> x >> y;
- variables.push_back(
- std::make_pair(x, y));
- }
- for (int i = 0; i < m; i++)
- {
- int x, y;
- cin >> x >> y;
- constants.push_back(
- std::make_pair(x, y));
- }
- Program lp(CGAL::SMALLER, true, 1, false, 0);
- int peri = 2 * h + 2 * w;
- for (int i = 0; i < n; i++)
- {
- // objective function
- lp.set_c(i, -peri);
- }
- int n_1 = n - 1;
- // Number of constraints
- int k = 0;
- // Variable to variable comparison
- for (int i = 0; i < n_1; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- // a_1 + a_2 <= 2 (p2x - p1x) / w
- lp.set_a(i, k, 1);
- lp.set_a(j, k, 1);
- lp.set_b(k,
- std::max(
- CGAL::Gmpq(
- std::abs(
- 2 * (variables[i].first - variables[j].first)),
- w),
- CGAL::Gmpq(
- std::abs(
- 2 * (variables[i].second - variables[j].second)),
- w)));
- k++;
- }
- }
- // Variable to constant comparison
- for (int i = 0; i < n; i++)
- {
- CGAL::Gmpq big(2000000000, 1);
- for (int j = 0; j < m; j++)
- {
- CGAL::Gmpq tmp = std::max(
- CGAL::Gmpq(
- std::abs((2) * (variables[i].first - constants[j].first)), w),
- CGAL::Gmpq(
- std::abs((2) * (variables[i].second - constants[j].second)), w));
- big = std::min(big, tmp);
- }
- lp.set_a(i, k, 1);
- lp.set_b(k, big - CGAL::Gmpq(1, 1));
- k++;
- }
- // solve the program, using ET as the exact type
- Solution s = CGAL::solve_linear_program(lp, ET());
- assert(s.solves_linear_program(lp));
- // cout << s << endl;
- cout << -(int)ceil(CGAL::to_double(s.objective_value())) << endl;
- }
- int main(int argc, char const *argv[])
- {
- ios_base::sync_with_stdio(false);
- int t;
- cin >> t;
- while (t--)
- testcase();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement