TopCoder problem "MaximizeSquares" used in SRM 362 (Division I Level One , Division II Level Two)



Problem Statement

    Consider an arrangement of N points on the cartesian plane. The "square count" of the points is the total number of distinct squares with sides parallel to the coordinate axes which can be built using 4 different points as vertices. Your task is to return the maximum square count, considering all possible arrangements of N points on the plane.
 

Definition

    
Class:MaximizeSquares
Method:squareCount
Parameters:int
Returns:int
Method signature:int squareCount(int N)
(be sure your method is public)
    
 

Notes

-Two squares are distinct if at least one of their corners is in a different location.
 

Constraints

-N will be between 0 and 1000000, inclusive.
 

Examples

0)
    
4
Returns: 1
Clearly, we can only make one square out of 4 points.
1)
    
5
Returns: 1
No matter where we place a fifth point, we can't get any extra squares.
2)
    
6
Returns: 2
We can get 2 squares by placing the points in the shape of a rectangle.
3)
    
16
Returns: 14
4)
    
115
Returns: 340

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7735

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10775&pm=7735

Writer:

eleusive

Testers:

PabloGilberto , Olexiy , lovro , ivan_metelsky

Problem categories:

Geometry, Greedy, Math