Connection Status:
Competition Arena > TreeLine
TCC19 India Qualifiers · 2019-05-04 · by erinn · Brute Force
Class Name: TreeLine
Return Type: int
Method Name: longest
Arg Types: (vector<int>, vector<int>)
Problem Statement

Problem Statement

A farmer has several trees planted, the locations of which are given in int[]s x and y, where (x[i], y[i]) indicates the location of the i-th tree. The farmer notices that some of them form straight lines with one another and wonders, what is the largest numver of trees that are perfectly colinear with each other?

Constraints

  • x will have between 1 and 50 elements, inclusive.
  • x and y will have 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 elements of x and y will refer to the same point.
Examples
0)
{0, 3, 6}
{0, 3, 6}
Returns: 3

All three trees for a line.

1)
{0, 3, 6}
{0, 3, 7}
Returns: 2

Notice the last tree is not in line with the first two.

2)
{0, 3, 6, 20, 12}
{0, 3, 0, 20, 11}
Returns: 3

Trees 0, 1 and 3 line up, the other two do not.

3)
{0, 3, 6, 20, 12}
{0, 3, 0, 19, 0}
Returns: 3
4)
{1}
{2}
Returns: 1

Submissions are judged against all 46 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TreeLine with a public method int longest(vector<int> x, vector<int> y) · 46 test cases · 2 s / 256 MB per case

Submitting as anonymous