Connection Status:
Competition Arena > PointsInAPlane
Rookie SRM 5 · 2021-05-12 · by t-mac · Geometry, Math
Class Name: PointsInAPlane
Return Type: int
Method Name: howManyTriangles
Arg Types: (vector<int>, vector<int>)
Problem Statement

Problem Statement

You are given a collection of points in the plane, with x[i] and y[i] representing the i-th point. Return the number of triangles that can be formed using three of the points as vertices.

Notes

  • Three points can only form a triangle if they are not colinear.

Constraints

  • x will contain between 1 and 50 elements, inclusive.
  • y will contain the same number of elements as x.
  • Each element of x will be between -1,000,000,000 and 1,000,000,000, inclusive.
  • Each element of y will be between -1,000,000,000 and 1,000,000,000, inclusive.
  • No two points will be at the same position.
Examples
0)
{0, 1, 2}
{0, 1, 0}
Returns: 1

These three points for a triangle.

1)
{0, 1, 2}
{0, 0, 0}
Returns: 0

These three points sit along the x-axis, and are all collinear.

2)
{0, 1, 2, 3}
{0, 2, 1, 3}
Returns: 4

Pick any three points, and they form a triangle.

3)
{0, 1, 2, 1}
{0, 0, 0, 1}
Returns: 3
4)
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49}
{0, 1, 2, 3, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 22, 4, 5, 6, 7, 8, 9, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 19, 20, 49}
Returns: 16880

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

Coding Area

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

Submitting as anonymous