题面
来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。
Problem
You are given an integer n. Place n unit squares (side length 1) inside an axis-parallel square container of side length L so that:
- Every unit square lies entirely inside the container.
- Unit squares have no common interior points (touching edges/corners is allowed).
- Each unit square may be rotated by an arbitrary angle.
Your goal is to minimize L.
Input
A single integer n (1 ≤ n ≤ 100000).
Output
- First line: a real number L (the claimed container side length).
- Next n lines: three real numbers xi, yi, ai for i = 1..n:
- (xi, yi) is the center of the i-th unit square.
- ai is its rotation angle in degrees counterclockwise, 0 ≤ ai < 180.
All numbers must be finite reals. Any reasonable precision is allowed; at least 6 decimal places is recommended.
Validity
Your output is valid if and only if:
- Containment: Every point of every unit square lies inside [0, L] × [0, L].
- Non-overlap (interiors): The interiors of any two unit squares are disjoint. Touching along edges or at corners is allowed.
- Angles: 0 ≤ ai < 180 for all i.
The judge verifies geometry with epsilon = 1e-7:
- Containment: A square is accepted if its maximum outward violation beyond the container is ≤ 1e-7.
- Non-overlap: Two squares are accepted as interior-disjoint if the minimum signed distance between their boundaries is ≥ −1e-7.
Invalid submissions score 0 for that test.
Goal
Minimize L subject to the validity constraints.
Baseline
A simple baseline packs all squares unrotated (ai = 0) on the unit grid, with centers at (0.5 + x, 0.5 + y), using the smallest integer-sided container that fits all n. The baseline side length is
- L0(n) = ceil(sqrt(n)).
For example, for n = 11, the baseline uses L0 = 4.000000.
## Scoring
Let x be L, the container side length. For non-square n, s(n) is the comparison side length stored with the test. It is the recorded comparison for n<=100 and uses s(n)=2*s(ceil(n/4)) for larger n; do not replace it by ceil(sqrt(n)). For square n, use the separate exact-target rule: 100 if L<=sqrt(n)+1e-12, otherwise 0. The physical reference (the 60-point level) is a=s(n). Define the lower-band continuation:
L(x) = 60*s(n)/x.
For positive x and positive physical reference a, define the improvement factor r=a/x. The physical reference has r=1 and earns 60 points. For a valid output on this branch, the points P are:
P = 100, if x=0;
P = L(x), if L(x)<=60;
P = min(100,60+ln(r)), otherwise.
Here ln is the natural logarithm. In the upper branch before the 100-point cap, r=exp(P-60): each additional point requires an e-fold improvement in the physical objective (division by e). All feasibility, correctness, and hard resource-limit checks remain required; invalid output receives 0.
Across test files, use the arithmetic mean of the file scores.
Time limit
1 second
Memory limit
512 MB
Sample
Input
11
Output
4.000000
0.500000 0.500000 0.000000
1.500000 0.500000 0.000000
2.500000 0.500000 0.000000
3.500000 0.500000 0.000000
0.500000 1.500000 0.000000
1.500000 1.500000 0.000000
2.500000 1.500000 0.000000
3.500000 1.500000 0.000000
0.500000 2.500000 0.000000
1.500000 2.500000 0.000000
2.500000 2.500000 0.000000
(The sample is a valid baseline packing for n = 11 with L = 4.000000.)
Additional clarifications
- Unit squares: Side length exactly 1, centered at (xi, yi), rotated by ai degrees around the center.
- Ordering: Squares may be listed in any order.
- Precision: Inputs are read as doubles; small rounding differences are tolerated per epsilon.
- Touching: Squares may touch each other and the container boundary; only interior overlap is forbidden.
Design notes (for organizers and contestants)
- The reference and integer-grid construction have different roles. Neither
is assumed to be the smallest possible side length for non-square n.
- Precision: the geometric validity tolerance remains 1e-7. The scoring ratio
is reported with twelve decimal places to retain small improvements.
结果
Kimi K3.1 ProKimi
max
59.0
平均得分 ↑
- 59.0采样 1 · 部分分
- 5.8k平均输出 token(含思考) ↓
- 28.2输出速度 tokens/s ↑
- 206 秒延迟 ↓
Kimi K3.1 Pro(high)Kimi high
high
59.3
平均得分 ↑
- 59.3采样 1 · 部分分
- 4.4k平均输出 token(含思考) ↓
- 28.2输出速度 tokens/s ↑
- 160 秒延迟 ↓
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
59.0
平均得分 ↑
- 59.0采样 1 · 部分分
- 19.3k平均输出 token(含思考) ↓
- 172.5输出速度 tokens/s ↑
- 113 秒延迟 ↓
MiniMax M3.1 FlashMiniMax
auto(max)
0.0
平均得分 ↑
- 0.0采样 1 · 编译错误
- 93.3k平均输出 token(含思考) ↓
- 109.5输出速度 tokens/s ↑
- 853 秒延迟 ↓
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 25 行
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; int k = static_cast<int>(sqrt(static_cast<double>(n))); while (k * k < n) ++k; while (k > 1 && (k - 1) * (k - 1) >= n) --k; cout << fixed << setprecision(10); cout << static_cast<double>(k) << '\n'; for (int i = 0; i < n; ++i) { int row = i / k; int col = i % k; cout << col + 0.5 << ' ' << row + 0.5 << " 0.0000000000\n"; } return 0; }
Kimi K3.1 Pro(high) · 采样 1 · 36 行
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; cout << fixed << setprecision(12); if (n == 5) { const double L = 2.0 + sqrt(0.5); cout << L << '\n'; cout << 0.5 << ' ' << 0.5 << ' ' << 0.0 << '\n'; cout << L - 0.5 << ' ' << 0.5 << ' ' << 0.0 << '\n'; cout << 0.5 << ' ' << L - 0.5 << ' ' << 0.0 << '\n'; cout << L - 0.5 << ' ' << L - 0.5 << ' ' << 0.0 << '\n'; cout << L / 2.0 << ' ' << L / 2.0 << ' ' << 45.0 << '\n'; return 0; } int m = static_cast<int>(ceil(sqrt(static_cast<double>(n)))); while (m * m < n) ++m; while (m > 1 && (m - 1) * (m - 1) >= n) --m; cout << m << '\n'; for (int i = 0; i < n; ++i) { int x = i % m; int y = i / m; cout << x + 0.5 << ' ' << y + 0.5 << ' ' << 0.0 << '\n'; } return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 26 行
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int L = 1; while ((long long)L * L < n) ++L; cout << fixed << setprecision(6); cout << L << "\n"; for (int i = 0; i < n; ++i) { int col = i % L; int row = i / L; double x = col + 0.5; double y = row + 0.5; cout << x << " " << y << " 0.000000\n"; } return 0; }
MiniMax M3.1 Flash · 采样 1 · 710 行
#include <bits/stdc++.h> using namespace std; static constexpr double PI = 3.1415926535897932384626433832795; static constexpr double INV_SQRT2 = 0.70710678118654752440084436210485; struct Square { double x, y, a; double ux, uy; void setAngle(double angle) { a = angle; ux = cos(a); uy = sin(a); } double extent() const { return 0.5 * (fabs(ux) + fabs(uy)); } }; struct Packing { vector<Square> squares; double L = 0.0; }; static void syncSquare(Square &s) { s.ux = cos(s.a); s.uy = sin(s.a); } static void normalize(Packing &p) { if (p.squares.empty()) { p.L = 0.0; return; } double minX = numeric_limits<double>::infinity(); double minY = numeric_limits<double>::infinity(); double maxX = -numeric_limits<double>::infinity(); double maxY = -numeric_limits<double>::infinity(); for (const auto &s : p.squares) { double h = s.extent(); minX = min(minX, s.x - h); maxX = max(maxX, s.x + h); minY = min(minY, s.y - h); maxY = max(maxY, s.y + h); } double dx = -minX; double dy = -minY; for (auto &s : p.squares) { s.x += dx; s.y += dy; } p.L = max(maxX + dx, maxY + dy); } static inline double dot(double ax, double ay, double bx, double by) { return ax * bx + ay * by; } static inline double separationMargin(const Square &a, const Square &b) { double dx = b.x - a.x; double dy = b.y - a.y; double best = -numeric_limits<double>::infinity(); auto consider = [&](double nx, double ny) { double ra = 0.5 * (fabs(dot(a.ux, a.uy, nx, ny)) + fabs(dot(-a.uy, a.ux, nx, ny))); double rb = 0.5 * (fabs(dot(b.ux, b.uy, nx, ny)) + fabs(dot(-b.uy, b.ux, nx, ny))); double margin = fabs(dx * nx + dy * ny) - ra - rb; best = max(best, margin); }; consider(a.ux, a.uy); consider(-a.uy, a.ux); consider(b.ux, b.uy); consider(-b.uy, b.ux); return best; } static bool quickValid(const Packing &p, double eps = 2e-8) { if (p.squares.empty() || !isfinite(p.L)) return false; for (const auto &s : p.squares) { double h = s.extent(); if (s.x - h < -eps || s.x + h > p.L + eps || s.y - h < -eps || s.y + h > p.L + eps) { return false; } } const double BIN = 1.5; int nx = max(2, (int)ceil(p.L / BIN) + 3); int ny = max(2, (int)ceil(p.L / BIN) + 3); vector<vector<int>> bins((size_t)nx * ny); for (int i = 0; i < (int)p.squares.size(); ++i) { const auto &s = p.squares[i]; int bx = (int)floor(s.x / BIN); int by = (int)floor(s.y / BIN); if (bx < 0) bx = 0; if (by < 0) by = 0; if (bx >= nx) bx = nx - 1; if (by >= ny) by = ny - 1; bins[(size_t)by * nx + bx].push_back(i); } auto testPair = [&](int i, int j) { return separationMargin(p.squares[i], p.squares[j]) >= -eps; }; for (int by = 0; by < ny; ++by) { for (int bx = 0; bx < nx; ++bx) { const auto &v = bins[(size_t)by * nx + bx]; for (int i = 0; i < (int)v.size(); ++i) { for (int j = i + 1; j < (int)v.size(); ++j) { if (!testPair(v[i], v[j])) return false; } } for (int oy = -1; oy <= 1; ++oy) { for (int ox = -1; ox <= 1; ++ox) { if (ox < 0 || (ox == 0 && oy < 0)) continue; if (ox == 0 && oy == 0) continue; int xx = bx + ox; int yy = by + oy; if (xx < 0 || xx >= nx || yy < 0 || yy >= ny) continue; const auto &w = bins[(size_t)yy * nx + xx]; for (int i : v) { for (int j : w) { if (!testPair(i, j)) return false; } } } } } } return true; } static int ceilSqrt(int n) { int r = (int)sqrt((double)n); while ((long long)r * r < n) ++r; while (r > 0 && (long long)(r - 1) * (r - 1) >= n) --r; return r; } static bool isPerfectSquare(int n) { int r = (int)sqrt((double)n); return (long long)r * r == n; } static Packing makeGrid(int n) { Packing p; int cols = ceilSqrt(n); int rows = ceilSqrt(n); int actualRows = (n + cols - 1) / cols; double L = cols; double offsetY = 0.5 * (L - actualRows); p.squares.reserve(n); for (int i = 0; i < n; ++i) { int r = i / cols; int c = i % cols; Square s; s.x = c + 0.5; s.y = r + 0.5 + offsetY; s.setAngle(0.0); p.squares.push_back(s); } normalize(p); return p; } static Packing trimToCount(Packing p, int target) { if ((int)p.squares.size() == target) { normalize(p); return p; } if ((int)p.squares.size() < target) return {}; double minX = numeric_limits<double>::infinity(); double minY = numeric_limits<double>::infinity(); double maxX = -numeric_limits<double>::infinity(); double maxY = -numeric_limits<double>::infinity(); for (const auto &s : p.squares) { double h = s.extent(); minX = min(minX, s.x - h); maxX = max(maxX, s.x + h); minY = min(minY, s.y - h); maxY = max(maxY, s.y + h); } double cx = 0.5 * (minX + maxX); double cy = 0.5 * (minY + maxY); int excess = (int)p.squares.size() - target; vector<int> order(p.squares.size()); iota(order.begin(), order.end(), 0); Packing best; best.L = numeric_limits<double>::infinity(); for (int strategy = 0; strategy < 8; ++strategy) { auto score = [&](int i) { double dx = p.squares[i].x - cx; double dy = p.squares[i].y - cy; switch (strategy) { case 0: return dx * dx + dy * dy; case 1: return fabs(dx); case 2: return fabs(dy); case 3: return dx + dy; case 4: return dx - dy; case 5: return -dx + dy; case 6: return -dx - dy; default: return fabs(dx) + fabs(dy); } }; nth_element(order.begin(), order.begin() + excess, order.end(), [&](int i, int j) { return score(i) > score(j); }); vector<char> removed(p.squares.size(), false); for (int i = 0; i < excess; ++i) removed[order[i]] = true; Packing q; q.squares.reserve(target); for (int i = 0; i < (int)p.squares.size(); ++i) { if (!removed[i]) q.squares.push_back(p.squares[i]); } normalize(q); if (q.squares.size() == target && quickValid(q) && q.L < best.L) { best = std::move(q); } } return best; } struct PairInfo { double margin; double nx, ny; int owner; int localAxis; }; static PairInfo getPairInfo(const Square &a, const Square &b) { double dx = b.x - a.x; double dy = b.y - a.y; PairInfo best{-numeric_limits<double>::infinity(), 0, 0, 0, 0}; auto consider = [&](double nx, double ny, int owner, int localAxis) { double ra = 0.5 * (fabs(dot(a.ux, a.uy, nx, ny)) + fabs(dot(-a.uy, a.ux, nx, ny))); double rb = 0.5 * (fabs(dot(b.ux, b.uy, nx, ny)) + fabs(dot(-b.uy, b.ux, nx, ny))); double margin = fabs(dx * nx + dy * ny) - ra - rb; if (margin > best.margin) { best = {margin, nx, ny, owner, localAxis}; } }; consider(a.ux, a.uy, 0, 0); consider(-a.uy, a.ux, 0, 1); consider(b.ux, b.uy, 1, 0); consider(-b.uy, b.ux, 1, 1); return best; } static bool relaxPacking(Packing &p, int iterations, chrono::steady_clock::time_point deadline) { const int n = (int)p.squares.size(); for (int iter = 0; iter < iterations; ++iter) { if ((iter & 7) == 0 && chrono::steady_clock::now() >= deadline) break; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { PairInfo info = getPairInfo(p.squares[i], p.squares[j]); if (info.margin >= -1e-10) continue; double penetration = -info.margin; double dx = p.squares[j].x - p.squares[i].x; double dy = p.squares[j].y - p.squares[i].y; double direction = dx * info.nx + dy * info.ny; double move = 0.55 * 0.5 * penetration + 1e-7; if (direction >= 0.0) { p.squares[i].x -= info.nx * move; p.squares[i].y -= info.ny * move; p.squares[j].x += info.nx * move; p.squares[j].y += info.ny * move; } else { p.squares[i].x += info.nx * move; p.squares[i].y += info.ny * move; p.squares[j].x -= info.nx * move; p.squares[j].y -= info.ny * move; } if (info.owner == 0 || info.owner == 1) { Square &owner = (info.owner == 0 ? p.squares[i] : p.squares[j]); const Square &other = (info.owner == 0 ? p.squares[j] : p.squares[i]); double axisAngle = owner.a + (info.localAxis ? PI / 2.0 : 0.0); double delta = other.a - axisAngle; double sc = cos(delta), ss = sin(delta); double dr = 0.5 * ((sc >= 0 ? 1.0 : -1.0) * ss - (ss >= 0 ? 1.0 : -1.0) * sc); double ox = other.x - owner.x; double oy = other.y - owner.y; double t = ox * info.nx + oy * info.ny; double tangent = ox * (-info.ny) + oy * info.nx; double derivative = dr - (t >= 0 ? 1.0 : -1.0) * tangent; double da = -0.075 * penetration * derivative; da = max(-0.025, min(0.025, da)); owner.setAngle(owner.a + da); } } } for (auto &s : p.squares) { double h = s.extent(); if (s.x < h) s.x = h; if (s.x > p.L - h) s.x = p.L - h; if (s.y < h) s.y = h; if (s.y > p.L - h) s.y = p.L - h; } } normalize(p); return quickValid(p); } static Packing optimizePacking(int n, chrono::steady_clock::time_point deadline) { Packing current = makeGrid(n); if (isPerfectSquare(n)) return current; mt19937 rng(712367821u); uniform_real_distribution<double> uni(-1.0, 1.0); double nominal = current.L; double lower = sqrt((double)n) + 1e-7; double step = min(0.03, max(0.002, (current.L - lower) * 0.18)); while (chrono::steady_clock::now() < deadline && nominal - step >= lower) { double target = max(lower, nominal - step); bool found = false; for (int attempt = 0; attempt < 3 && !found; ++attempt) { Packing q = current; double factor = target / nominal; double oldCenter = nominal * 0.5; double newCenter = target * 0.5; for (auto &s : q.squares) { s.x = newCenter + (s.x - oldCenter) * factor; s.y = newCenter + (s.y - oldCenter) * factor; } if (attempt == 1) { for (auto &s : q.squares) { s.x += 0.012 * uni(rng); s.y += 0.012 * uni(rng); s.setAngle(s.a + 0.008 * uni(rng)); } } else if (attempt == 2) { int cols = ceilSqrt(n); int rows = (n + cols - 1) / cols; double cw = target / cols; double ch = target / rows; for (int i = 0; i < (int)q.squares.size(); ++i) { int r = i / cols, c = i % cols; q.squares[i].x = (c + 0.5) * cw + 0.025 * uni(rng); q.squares[i].y = (r + 0.5) * ch + 0.025 * uni(rng); q.squares[i].setAngle(0.012 * uni(rng)); } } q.L = target; if (relaxPacking(q, 180, deadline)) { current = std::move(q); nominal = target; found = true; } } if (found) { step = min(0.03, step * 1.08); } else { step *= 0.5; if (step < 0.00015) break; } } normalize(current); return current; } static int cornerCapacity(int s) { if (s <= 0) return 0; return (s / 2) * ((s + 1) / 2); } struct TemplateSpec { int P, Q, s1, s2; double L; }; static Packing makeTemplate(const TemplateSpec &spec, int target, int variant) { int w1 = spec.s1 / 2; int h1 = spec.s1 - w1; int w2 = spec.s2 / 2; int h2 = spec.s2 - w2; if (variant & 1) swap(w1, h1); if (variant & 2) swap(w2, h2); Packing p; p.L = spec.L; double ux = INV_SQRT2, uy = INV_SQRT2; double vx = -INV_SQRT2, vy = INV_SQRT2; double cx = spec.L * 0.5, cy = spec.L * 0.5; for (int i = 0; i < spec.P; ++i) { for (int j = 0; j < spec.Q; ++j) { double du = i - 0.5 * (spec.P - 1); double dv = j - 0.5 * (spec.Q - 1); Square s; s.x = cx + du * ux + dv * vx; s.y = cy + du * uy + dv * vy; s.setAngle(PI / 4.0); p.squares.push_back(s); } } auto addRectangle = [&](double x0, double y0, int w, int h) { for (int i = 0; i < w; ++i) { for (int j = 0; j < h; ++j) { Square s; s.x = x0 + i + 0.5; s.y = y0 + j + 0.5; s.setAngle(0.0); p.squares.push_back(s); } } }; addRectangle(0.0, 0.0, w1, h1); addRectangle(spec.L - w2, 0.0, w2, h2); addRectangle(spec.L - w1, spec.L - h1, w1, h1); addRectangle(0.0, spec.L - h2, w2, h2); normalize(p); if ((int)p.squares.size() > target) p = trimToCount(std::move(p), target); else normalize(p); if ((int)p.squares.size() != target || !quickValid(p)) return {}; return p; } static vector<Packing> makeDeterministicBases(int n) { vector<Packing> result; result.push_back(makeGrid(n)); int root = ceilSqrt(n); int maxP = min(10, root); int maxS = root + 3; vector<TemplateSpec> specs; for (int P = 1; P <= maxP; ++P) { if (P * Q > n) continue; for (int Q = 1; Q <= maxP; ++Q) { if (P * Q > n) continue; for (int s1 = 0; s1 <= maxS; ++s1) { for (int s2 = 0; s2 <= maxS; ++s2) { int cap = P * Q + 2 * cornerCapacity(s1) + 2 * cornerCapacity(s2); if (cap < n) continue; double L = max({ s1 + P * INV_SQRT2, s2 + Q * INV_SQRT2, (P + Q) * INV_SQRT2 }); if (L > root + 1.0) continue; specs.push_back({P, Q, s1, s2, L}); } } } } sort(specs.begin(), specs.end(), [](const auto &x, const auto &y) { return x.L < y.L; }); int processed = 0; for (const auto &spec : specs) { bool added = false; for (int variant = 0; variant < 4; ++variant) { Packing p = makeTemplate(spec, n, variant); if (p.squares.empty()) continue; result.push_back(std::move(p)); added = true; } if (added && ++processed >= 80) break; } sort(result.begin(), result.end(), [](const auto &x, const auto &y) { return x.L < y.L; }); if (result.size() > 24) result.resize(24); return result; } static Packing transformPacking(const Packing &base, int scale) { Packing p; p.squares.reserve(base.squares.size() * (size_t)scale * scale); double half = 0.5 * (scale - 1); for (const auto &b : base.squares) { for (int i = 0; i < scale; ++i) { for (int j = 0; j < scale; ++j) { double du = i - half; double dv = j - half; Square s; s.x = b.x * scale + du * b.ux - dv * b.uy; s.y = b.y * scale + du * b.uy + dv * b.ux; s.setAngle(b.a); p.squares.push_back(s); } } } normalize(p); return p; } static Packing makeSingleDiamondPattern(int n) { if (n < 5) return {}; int q = ceilSqrt(n); if (q < 2) q = 2; if ((q & 1) != 0) ++q; int a = q / 2; int capacity = 4 * a * a + 1; if (capacity != n) return {}; double L = q + INV_SQRT2; Packing p; p.L = L; auto addRectangle = [&](double x0, double y0) { for (int i = 0; i < a; ++i) { for (int j = 0; j < a; ++j) { Square s; s.x = x0 + i + 0.5; s.y = y0 + j + 0.5; s.setAngle(0.0); p.squares.push_back(s); } } }; addRectangle(0.0, 0.0); addRectangle(L - a, 0.0); addRectangle(L - a, L - a); addRectangle(0.0, L - a); Square middle; middle.x = middle.y = L * 0.5; middle.setAngle(PI / 4.0); p.squares.push_back(middle); normalize(p); if (!quickValid(p)) return {}; return p; } static void appendNumber(string &out, double value, int precision) { char buffer[64]; auto result = to_chars(buffer, buffer + sizeof(buffer), value, chars_format::fixed, precision); out.append(buffer, result.ptr); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; auto deadline = chrono::steady_clock::now() + chrono::milliseconds(560); Packing best = makeGrid(n); if (!isPerfectSquare(n)) { Packing special = makeSingleDiamondPattern(n); if (!special.squares.empty() && special.L < best.L) { best = std::move(special); } } int reduced = n; int levels = 0; while (reduced > 100) { reduced = (reduced + 3) / 4; ++levels; } vector<Packing> bases = makeDeterministicBases(reduced); if (!isPerfectSquare(reduced)) { Packing improved = optimizePacking(reduced, deadline); if (!improved.squares.empty() && improved.L < bases.front().L) { bases.insert(bases.begin(), std::move(improved)); } } sort(bases.begin(), bases.end(), [](const auto &x, const auto &y) { return x.L < y.L; }); if (bases.size() > 18) bases.resize(18); if (levels == 0) { for (auto &base : bases) { if (!base.squares.empty() && base.L < best.L) { best = std::move(base); } } } else { int currentReduced = reduced; int scale = 1 << levels; for (int extra = 0; extra < 4; ++extra) { vector<Packing> levelBases; if (extra == 0) { levelBases = bases; } else { currentReduced = (currentReduced + 3) / 4; scale *= 4; if (currentReduced < 2) break; levelBases = makeDeterministicBases(currentReduced); if (levelBases.size() > 8) levelBases.resize(8); } for (const auto &base : levelBases) { if (base.squares.empty()) continue; if ((double)scale * base.L > best.L * 1.25) continue; Packing transformed = transformPacking(base, scale); if ((int)transformed.squares.size() < n) continue; transformed = trimToCount(std::move(transformed), n); if (transformed.squares.empty()) continue; if (!quickValid(transformed)) continue; if (transformed.L < best.L) { best = std::move(transformed); } } } } normalize(best); string output; output.reserve((size_t)n * 52 + 128); appendNumber(output, best.L, 12); output.push_back('\n'); for (const auto &s : best.squares) { appendNumber(output, s.x, 10); output.push_back(' '); appendNumber(output, s.y, 10); output.push_back(' '); double angle = atan2(s.uy, s.ux) * 180.0 / PI; if (angle < 0.0) angle += 360.0; while (angle >= 180.0) angle -= 180.0; while (angle < 0.0) angle += 180.0; if (angle >= 179.999999999) angle = 0.0; appendNumber(output, angle, 10); output.push_back('\n'); } fwrite(output.data(), 1, output.size(), stdout); return 0; }