RectangleHunt
SRM 764 · 2019-08-09 · by erinn
SRM 764 · 2019-08-09 · by erinn · Brute Force
Problem Statement
Problem Statement
You are given a set of points, given as (x, y) coordinates in int[]s x and y.
Return the area of the largest rectangle that can be formed from four of the points. If no four points can form a rectangle, return -1.
Notes
- Your return value must be within 1e-9 absolute or relative error to be considered correct.
Constraints
- x will contain between 4 and 50 elements, inclsuive.
- x and y will contain the same number of elements.
- Each element of x will be between 0 and 1000, inclusive.
- Each element of y will be between 0 and 1000, inclusive.
- No two points specified by x and y will be the same.
Examples
0)
{0, 1, 0, 1}
{0, 2, 2, 0}
Returns: 2.0
There is only a single rectangle, 2x1 in size.
1)
{0, 1, 0, 1}
{0, 2, 2, 3}
Returns: -1.0
These four points don't form a rectangle.
2)
{0, 5, 6, 11}
{5, 2, 15, 12}
Returns: 68.0
The rectangle isn't necessarily aligned along the x-y grid.
3)
{1, 2, 3, 4}
{1, 2, 3, 4}
Returns: -1.0
4)
{0, 50, 60, 110}
{50, 20, 150, 120}
Returns: 6800.0
Submissions are judged against all 39 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class RectangleHunt with a public method double largest(vector<int> x, vector<int> y) · 39 test cases · 2 s / 256 MB per case