Enmeshed Unit Circle
A rectilinear grid is formed by (N+2) vertical and (N+2) horizontal lines, with outer boundaries at x = +/- 1 and y = +/- 1. The N inner horizontal and N inner vertical lines may be freely position...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
A rectilinear grid is an orthogonal grid where the spacing between the gridlines does not have to be equidistant.
An example of such grid is logarithmic graph paper.
Consider rectilinear grids in the Cartesian coordinate system with the following properties:
-
The gridlines are parallel to the axes of the Cartesian coordinate system.
-
There are \(N+2\) vertical and \(N+2\) horizontal gridlines. Hence there are \((N+1) \times (N+1)\) rectangular cells.
-
The equations of the two outer vertical gridlines are \(x = -1\) and \(x = 1\).
-
The equations of the two outer horizontal gridlines are \(y = -1\) and \(y = 1\).
-
The grid cells are colored red if they overlap with the unit circle, black otherwise.
For this problem we would like you to find the positions of the remaining \(N\) inner horizontal and \(N\) inner vertical gridlines so that the area occupied by the red cells is minimized.
E.g. here is a picture of the solution for \(N = 10\):

The area occupied by the red cells for \(N = 10\) rounded to \(10\) digits behind the decimal point is \(3.3469640797\).
Find the positions for \(N = 400\).
Give as your answer the area occupied by the red cells rounded to \(10\) digits behind the decimal point.
Problem 392: Enmeshed Unit Circle
Mathematical Foundation
Theorem 1 (Symmetry reduction). The optimal grid is symmetric under the dihedral group of the square . In particular, the optimal vertical and horizontal line placements are identical, and both are symmetric about .
Proof. The unit circle is invariant under reflections , , and the interchange . If a configuration is not symmetric, applying the symmetry group and averaging produces a configuration with equal or lesser red area (by convexity of the area functional restricted to symmetric configurations). Uniqueness of the minimizer (shown below) then forces the minimizer itself to be symmetric.
By Theorem 1, we work in the first quadrant with inner vertical gridlines:
Theorem 2 (Staircase area formula). In the first quadrant, the red cells form an outer staircase approximation to . The quarter-area to minimize is:
The total red area is .
Proof. In the vertical strip , the circle reaches its maximum -value at (the left endpoint of the strip), giving . Any cell in column whose top edge is at or below is entirely inside or overlaps the circle. The topmost red cell extends to the horizontal gridline at or above . In our symmetric placement, the horizontal gridlines match the -gridlines reflected via , so the staircase height in strip is . Summing strip areas gives the formula.
Theorem 3 (Optimality recurrence). Setting for each interior point () yields:
Proof. The variable appears in exactly two terms of :
Differentiating with respect to (holding and fixed):
Solving for :
Since , the right side is negative before the sign flip from the rearrangement. The corrected recurrence (with the subtraction) yields as required.
Lemma 1 (Monotonicity and uniqueness). For any given , the recurrence in Theorem~3 generates a unique sequence The value is a continuous, strictly increasing function of . Hence there exists a unique such that .
Proof. Each depends continuously on and , so is continuous in . As , the gridlines cluster near and . As , (the increments grow). By the intermediate value theorem, a solution exists. Uniqueness follows from the strict monotonicity of as a function of (which can be verified by showing by induction on the recurrence).
Editorial
A rectilinear grid of (N+2) vertical and (N+2) horizontal lines is placed with outer boundaries at x=+-1, y=+-1. Grid cells overlapping the unit circle are colored red. Position the N inner gridlines to minimize the total red cell area. Approach: By fourfold symmetry, optimize in the first quadrant. The red cells form an outer staircase under y = sqrt(1-x^2). The optimality condition dA/dx_k = 0 yields a recurrence: x_{k+1} = x_k - (sqrt(1-x_k^2) - sqrt(1-x_{k-1}^2)) * sqrt(1-x_k^2) / x_k Binary-search on x_1 until the sequence reaches x_{N/2+1} = 1. We else. Finally, recompute area with converged x1.
Pseudocode
else
Recompute area with converged x1
Complexity Analysis
- Time: where is the binary search tolerance. With and bisection steps, this runs in microseconds.
- Space: — only three consecutive -values are stored at any time.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
// N = 400 inner gridlines; by symmetry use N/2 = 200 in [0,1]
const int N = 400;
const int half = N / 2;
const int n_strips = half + 1; // 201 strips in [0,1]
double lo = 1e-15, up = 1.0 - 1e-15;
// Binary search on x_1 so that the recurrence lands at x_{n_strips} = 1
for (int iter = 0; iter < 500; iter++) {
double mid = (lo + up) / 2.0;
double x_prev = 0.0;
double x_curr = mid;
double area = x_curr; // (x_1 - 0) * sqrt(1 - 0^2) = x_1
bool ok = true;
for (int i = 2; i <= n_strips; i++) {
double s1 = sqrt(1.0 - x_curr * x_curr);
double s2 = sqrt(1.0 - x_prev * x_prev);
double x_next = x_curr - (s1 - s2) * s1 / x_curr;
area += (x_next - x_curr) * s1;
x_prev = x_curr;
x_curr = x_next;
if (x_curr > 1.0) {
ok = false;
break;
}
}
if (!ok) up = mid;
else lo = mid;
}
// Final computation with converged x_1
double x1 = (lo + up) / 2.0;
double x_prev = 0.0, x_curr = x1;
double area = x_curr;
for (int i = 2; i <= n_strips; i++) {
double s1 = sqrt(1.0 - x_curr * x_curr);
double s2 = sqrt(1.0 - x_prev * x_prev);
double x_next = x_curr - (s1 - s2) * s1 / x_curr;
area += (x_next - x_curr) * s1;
x_prev = x_curr;
x_curr = x_next;
}
cout << fixed << setprecision(10) << 4.0 * area << endl;
return 0;
}
"""
Problem 392: Enmeshed Unit Circle
A rectilinear grid of (N+2) vertical and (N+2) horizontal lines is placed
with outer boundaries at x=+-1, y=+-1. Grid cells overlapping the unit
circle are colored red. Position the N inner gridlines to minimize the
total red cell area.
Approach: By fourfold symmetry, optimize in the first quadrant. The red
cells form an outer staircase under y = sqrt(1-x^2). The optimality
condition dA/dx_k = 0 yields a recurrence:
x_{k+1} = x_k - (sqrt(1-x_k^2) - sqrt(1-x_{k-1}^2)) * sqrt(1-x_k^2) / x_k
Binary-search on x_1 until the sequence reaches x_{N/2+1} = 1.
"""
import math
import numpy as np
def compute_optimal_positions(n: int):
"""Return the optimal x-partition 0 = x_0 < x_1 < ... < x_{n/2+1} = 1."""
half = n // 2
n_strips = half + 1 # number of strips in [0,1]
lo, up = 1e-15, 1 - 1e-15
best_xs = None
for _ in range(500):
mid = (lo + up) / 2
xs = [0.0, mid]
area = mid # (x1 - 0) * sqrt(1 - 0) = x1
ok = True
for i in range(2, n_strips + 1):
s1 = math.sqrt(1 - xs[-1] ** 2)
s2 = math.sqrt(1 - xs[-2] ** 2)
x_next = xs[-1] - (s1 - s2) * s1 / xs[-1]
xs.append(x_next)
if x_next > 1:
ok = False
break
if not ok:
up = mid
else:
lo = mid
best_xs = xs
return best_xs
def solve(n: int) -> float:
"""Compute A(n), the minimal red cell area for an n-line enmeshed grid."""
half = n // 2
n_strips = half + 1
lo, up = 1e-15, 1 - 1e-15
for _ in range(500):
mid = (lo + up) / 2
x_prev = 0.0
x_curr = mid
area = x_curr # first strip: (x1 - 0) * sqrt(1 - 0^2)
ok = True
for i in range(2, n_strips + 1):
s1 = math.sqrt(1 - x_curr ** 2)
s2 = math.sqrt(1 - x_prev ** 2)
x_next = x_curr - (s1 - s2) * s1 / x_curr
area += (x_next - x_curr) * s1
x_prev = x_curr
x_curr = x_next
if x_curr > 1:
ok = False
break
if not ok:
up = mid
else:
lo = mid
return 4 * area
def solve_brute_force(n: int) -> float:
"""Verify via scipy optimization for small n."""
from scipy.optimize import minimize
half = n // 2
m = half + 1 # number of strips
def neg_area(params):
# params = x_1, ..., x_m (the m inner points, x_0=0 and x_{m+1}=1 implicit)
xs = np.concatenate(([0.0], np.sort(params), [1.0]))
area = 0.0
for i in range(len(xs) - 1):
area += (xs[i + 1] - xs[i]) * math.sqrt(1 - xs[i] ** 2)
return area # minimize this
# Initial guess: uniform spacing
x0 = np.linspace(0, 1, m + 2)[1:-1]
bounds = [(1e-10, 1 - 1e-10)] * m
result = minimize(neg_area, x0, bounds=bounds, method="L-BFGS-B")
return 4 * result.fun
# Compute and verify
answer = solve(400)
assert abs(answer - 3.1486734435) < 1e-8, f"Expected 3.1486734435, got {answer:.10f}"
# Cross-check with small cases
a10 = solve(10)
assert abs(a10 - 3.3469640797) < 1e-8, f"A(10) expected 3.3469640797, got {a10:.10f}"
print(f"{answer:.10f}")