TopcoderARCHIVE
Archive/Problems/PointsInAPlane
SRM · Problem 13429

PointsInAPlane

Problem statement, definition, constraints, and public examples.

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.

Definition

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

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

  1. {0, 1, 2}
    {0, 1, 0}
    Returns: 1
    These three points for a triangle.
  2. {0, 1, 2}
    {0, 0, 0}
    Returns: 0
    These three points sit along the x-axis, and are all collinear.
  3. {0, 1, 2, 3}
    {0, 2, 1, 3}
    Returns: 4
    Pick any three points, and they form a triangle.
  4. {0, 1, 2, 1}
    {0, 0, 0, 1}
    Returns: 3
← All problems