Statistics

Problem Statement for "TriangleCounting"

Problem Statement

You are given a set of points in int[]s x and y, where each (x[i], y[i]) are the coordinates of one of the points. A set of three points form a triangle if and only if they are not colinear.

Return the number of ways you can select three of the given points to form a triangle.

Definition

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

Constraints

  • x will contain between 1 and 50 elements, inclusive.
  • x and y will contain the same number of elements.
  • Each element of x and y will be between 0 and 1000, inclusive.

Examples

  1. { 0, 2, 4 }

    { 0, 5, 3 }

    Returns: 1

    There's exactly three points, and they form a triangle.

  2. { 0, 2, 4, 6 }

    { 0, 5, 3, 15 }

    Returns: 3

    There's four ways to select three points here, but note that the points (0,0), (2,5), (6,15) are colinear, and thus don't form a triangle. So there are only three good sets to select.

  3. { 0, 2, 6 }

    { 0, 5, 15 }

    Returns: 0

    Here, we have only a single set to select, and those three points are colinear, so there are no triangles to speak of.

  4. { 0, 2, 4, 6, 8 }

    { 0, 5, 3, 15, 6 }

    Returns: 8

  5. { 0, 1, 2, 3, 4, 5, 6 }

    { 1, 2, 3, 4, 5, 6, 7 }

    Returns: 0

    Lots of points, but they're all on a single line, so none can form a triangle.

  6. { 0, 0, 1 }

    { 0, 0, 1 }

    Returns: 0

    Two of the points are at the same location, so, of course, they don't form a triangle.

  7. {76,678,453,964,499,70,618,323,942,992,35,708,806,493,141,173,530,116,115,558,233,93,998,822,71,115,313,190,31,535,3,887,793,911,920,687,794,895,8,429,147,104,805,211,602,594,510,491,385,740}

    {568,887,590,531,812,984,680,632,892,384,758,428,292,406,988,149,915,896,574,454,380,635,108,687,411,128,289,787,219,478,605,822,805,292,967,117,297,262,98,936,7,161,2,625,671,720,813,398,224,453}

    Returns: 19600

  8. {679,614,917,931,360,933,779,903,120,684,695,894,413,414,779,936,623,1000,439,871,853,653,797,639,447,218,633,483,15,691,315,891,562,766,799,991,906,875,933,34,339,394,141,415,241,113,749,589,846,736}

    {97,813,959,354,601,25,817,278,483,141,300,295,888,429,368,804,332,648,615,788,30,748,67,405,531,459,512,382,398,334,470,43,638,279,593,502,933,208,165,774,173,627,391,791,735,44,506,712,46,437}

    Returns: 19599

  9. {782,100,975,57,706,350,746,554,823,142,514,435,881,149,672,256,657,608,837,866,872,123,483,841,614,403,356,276,670,487,953,800,335,961,552,369,68,580,574,243,757,379,385,22,259,739,747,242,118,478}

    {387,899,876,181,565,658,618,133,443,303,994,469,884,336,190,715,99,920,597,303,188,77,34,593,109,493,738,460,582,876,656,114,158,192,100,54,924,154,395,894,752,935,136,271,250,287,495,49,833,545}

    Returns: 19600

  10. {640,828,645,816,290,309,864,282,71,72,921,157,552,568,647,879,311,692,236,135,791,946,524,703,551,253,941,764,343,822,998,688,627,36,236,829,469,342,902,791,190,642,82,323,974,594,383,569,624,371}

    {977,804,814,697,754,694,303,942,264,37,369,100,940,250,74,232,531,515,332,819,410,969,790,445,946,149,863,201,730,958,870,371,139,973,846,194,875,930,282,542,525,527,77,865,421,90,702,833,248,741}

    Returns: 19600

  11. {63,869,237,806,962,7,13,368,752,605,831,102,212,307,167,998,961,968,404,880,358,601,232,790,293,883,891,926,24,856,447,30,953,989,895,1,134,334,10,839,181,506,177,678,711,423,315,771,698,424}

    {129,735,428,369,383,462,636,447,512,79,116,88,344,897,157,800,149,224,412,165,863,626,957,566,699,852,423,555,78,870,568,120,227,601,726,713,603,584,605,433,365,687,822,932,723,93,161,281,520,911}

    Returns: 19600

  12. {274,91,358,532,561,504,778,863,670,531,38,81,369,643,511,996,861,744,171,445,197,565,619,980,800,176,804,24,844,605,691,142,34,167,595,477,762,696,40,222,935,741,914,73,394,284,318,179,420,727}

    {233,418,110,74,714,709,472,379,732,385,700,753,19,65,841,896,46,201,47,34,234,164,704,949,510,457,652,545,585,516,858,625,605,116,372,272,31,961,454,887,4,382,964,656,523,182,721,849,233,498}

    Returns: 19600

  13. {237,117,131,385,492,68,715,161,564,256,57,927,794,216,527,74,148,903,694,569,865,86,748,161,30,852,201,48,426,328,736,803,312,86,278,741,494,219,625,303,557,871,396,197,829,77,588,747,128,448}

    {33,819,155,664,634,151,369,970,355,640,867,667,736,236,520,254,615,708,939,787,580,929,277,390,11,994,691,550,332,953,264,454,920,978,295,918,648,648,452,126,371,524,865,985,436,891,134,160,677,574}

    Returns: 19600

  14. {463,881,809,342,868,104,541,765,653,640,461,820,637,402,376,413,747,758,941,603,607,967,255,812,415,56,64,293,954,121,860,530,873,759,490,383,646,578,109,190,377,883,996,812,666,552,887,462,609,23}

    {143,377,219,74,968,496,625,998,927,812,39,248,812,531,781,931,947,879,913,993,768,169,648,751,226,724,972,444,145,864,169,603,684,930,979,483,311,799,792,994,759,648,651,298,150,128,71,464,30,736}

    Returns: 19600

  15. {605,7,550,616,256,974,729,469,849,243,525,181,852,63,642,437,564,882,553,298,620,148,87,919,234,119,518,350,600,97,652,507,413,410,259,162,53,67,674,4,754,843,950,548,469,577,797,588,656,714}

    {565,190,912,733,115,456,921,631,381,137,455,379,869,751,592,17,769,441,804,480,384,496,207,549,545,777,198,540,450,658,323,931,694,886,533,461,596,681,294,803,241,422,686,537,549,375,974,199,957,451}

    Returns: 19599

  16. {808,355,784,176,330,68,984,362,188,339,258,380,181,724,815,525,685,983,218,130,422,88,147,1,238,962,810,671,1000,169,804,1000,584,999,850,968,146,518,556,464,478,233,493,956,545,861,241,963,723,23}

    {691,991,981,826,29,720,208,783,938,369,258,312,363,18,535,258,797,183,875,847,379,167,427,754,653,188,596,191,457,377,720,848,949,976,479,813,18,758,969,130,760,363,580,187,205,165,871,474,421,286}

    Returns: 19600

  17. {1, 2, 2 }

    {1, 2, 0 }

    Returns: 1

  18. {0, 1, 2 }

    {0, 1, 2 }

    Returns: 0

  19. {0, 0, 0 }

    {0, 0, 0 }

    Returns: 0

  20. {0, 1, 2 }

    {0, 2, 0 }

    Returns: 1

  21. {0, 2, 4, 6, 8 }

    {0, 5, 3, 15, 6 }

    Returns: 8

  22. {0, 1, 1, 2 }

    {0, 1, 1, 0 }

    Returns: 2

  23. {0, 2, 2 }

    {0, 12, 13 }

    Returns: 1

  24. {0, 0, 1, 0 }

    {0, 0, 0, 1 }

    Returns: 2


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: