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 69 70 71 72 73 74 75 76 77 78 79 80
| #include "geometry/halfplane.hpp" #include "geometry/line.hpp" #include "geometry/real.hpp" #include "geometry/vec.hpp" #include <iostream> #include <tuple> #include <vector> using namespace geometry; using i64 = long long;
int n, steps = 90; std::vector<line> lines; polygon poly; bool verdict;
int main() { std::cin >> n; if (n == 1) { std::cout << "1 1" << std::endl; int rx, ry; std::cin >> rx >> ry; return 0; }
double tn = n; lines.push_back(from_points(vec{1, 1}, vec{tn, 1})); lines.push_back(from_points(vec{tn, 1}, vec{tn, tn})); lines.push_back(from_points(vec{tn, tn}, vec{1, tn})); lines.push_back(from_points(vec{1, tn}, vec{1, 1}));
i64 l = 1e18, r = -1e18, u = -1e18, d = 1e18; double pa = -1;
while (steps) { std::tie(lines, poly, verdict) = solve_halfplane(lines); double a = area(poly); double ratio = (pa - a) / pa * 100; l = 1e18, r = -1e18, u = -1e18, d = 1e18; for (auto [x, y] : poly) { l = min(l, std::round(x)); r = max(r, std::round(x)); u = max(u, std::round(y)); d = min(d, std::round(y)); }
i64 rem = (r - l + 1) * (u - d + 1); if (rem <= steps) break;
i64 x = (l + r + 1) / 2, y = (u + d + 1) / 2, rx, ry; if (sign(pa, -1) != 0 && sign(ratio, 10) <= 0) { i64 tx = x, ty = y; while (tx == x && ty == y) { x += rand() % 3 - 1; y += rand() % 3 - 1; } } std::cout << x << " " << y << std::endl; steps--; std::cin >> rx >> ry;
if (x == rx && y == ry) return 0; i64 dx = rx - x, dy = ry - y; i64 ddx = dy, ddy = -dx;
lines.push_back(from_points(vec{x * 1.0, y * 1.0}, vec{1.0 * (x + ddx), 1.0 * (y + ddy)})); pa = a; }
for (int i = l; i <= r; i++) { for (int j = d; j <= u; j++) { std::cout << i << " " << j << std::endl; steps--; if (steps < 0) return 0; int rx, ry; std::cin >> rx >> ry; if (rx == i && ry == j) return 0; } } }
|