patternMinor
Maximum circular area sum
Viewed 0 times
circularmaximumareasum
Problem
Given an $n \times n$ grid of integers, I would like to compute the circular area which gives the maximum sum of integers within the area. For example:
In this picture, the integers 1, 0, 1, 2, 3, 1, 2, 1, -3, -2, 2, -3, 1, 3, -2, 0, 2, -1 etc are all within the circular area.
If we restrict the circular area to be centered at one of the grid points, is there an efficient algorithm for this problem?
The input is just the grid of integers. The task is to find the center and radius. If the circular area includes part outside the grid that part contributes zero to the sum.
In this picture, the integers 1, 0, 1, 2, 3, 1, 2, 1, -3, -2, 2, -3, 1, 3, -2, 0, 2, -1 etc are all within the circular area.
If we restrict the circular area to be centered at one of the grid points, is there an efficient algorithm for this problem?
The input is just the grid of integers. The task is to find the center and radius. If the circular area includes part outside the grid that part contributes zero to the sum.
Solution
There are $n^4$ possible $(x, y, r^2)$ tuple, each describing a circle centered at $(x, y)$ with radius $r$. Since each circle is its smaller version added with $O(1)$ additional points, this yields a time complexity of $O(n^4)$. We may find the additional points by sorting every $r^2 = a^2 + b^2$ pair.
Context
StackExchange Computer Science Q#164698, answer score: 2
Revisions (0)
No revisions yet.