TopCoder problem "FrogDerby" used in TCHS SRM 18 (Division I Level Two)



Problem Statement

    

You decided to put your pet frog in a frog derby. One of the objectives is to gather as many points as possible by repeatedly jumping in one constant direction, by a positive distance (which doesn't change from jump to jump). Your frog will receive points for occupying locations given in int[] x and int[] y, where x[i] and y[i] are the coordinates of the i-th location. If a single location occurs multiple times in x and y, then for each occurrence one point is awarded (see example 2).

The initial position of the frog is (0,0). Return the maximum amount of points that your frog can gather.

 

Definition

    
Class:FrogDerby
Method:getPoints
Parameters:int[], int[]
Returns:int
Method signature:int getPoints(int[] x, int[] y)
(be sure your method is public)
    
 

Constraints

-x and y will contain the same number of elements.
-x and y will each contain between 2 and 50 elements, inclusive.
-Each element of x and y will be between -106 and 106, inclusive.
 

Examples

0)
    
{1,0,0}
{0,1,0}
Returns: 2
The frog gets one point for occupying location (0,0). Then it has to choose between one of the two other points.
1)
    
{-1,1}
{0,0}
Returns: 1
2)
    
{1, 3, 4, 8, 4}
{0, 0, 1, 2, 1}
Returns: 3
If the frog will jump in the positive x direction, it will collect 2 points for locations (1, 0) and (3, 0). On the other hand, the frog can collect 3 points if jumping in the direction of location (4,1).
3)
    
{5, -4, 6, -9, -8, -6, -1, -4, 3, -924,
9, 8, 0, -129, 65, -313, 759, 8, -8, 5,
-9, -9, 2, -667, 798, -6, 231, 7, -209, -623,
0, 4, 0, -9, 159, -553, 787, 983, 356, -4, 3,
5, -98, -10, -3, -337, -874, -545, -5, -4}
{-504, 274, 5, -9, 572, -9, 90, -3, -10, 241,
113, -581, -755, -7, 240, -3, -54, 575, 5, 3,
3, 5, -7, -961, -3, -2, 9, 587, 4, -3,
214, -283, 115, 747, 2, -1, -52, 504, -8,
153, 494, 821, -760, 893, 1, 5, 338, -4, 974, 734}
Returns: 2
4)
    
{-14, -10, 15}
{7, 5, 0}
Returns: 2
5)
    
{-1,1,-2,-2,3,4,0,4,2,4,-2,-3}
{4,-3,-3,-2,3,4,-2,-3,2,4,-1,0}
Returns: 4
6)
    
{-1000000,-1000000}
{-1000000,-1000000}
Returns: 2
7)
    
{1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,
 4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7}
{-2,-3,-4,-5,-6,-7,-1,-3,-4,-5,-6,-7,-1,-2,-4,-5,-6,-7,
 -1,-2,-3,-5,-6,-7,-1,-2,-3,-4,-6,-7,-1,-2,-3,-4,-5,-7,-1,-2,-3,-4,-5,-6}
Returns: 3

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10070&pm=6829

Writer:

rusolis

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Math, Simple Search, Iteration