Problem Statement
You will be given a int[] X1, a int[] Y1, a int[] X2 and a int[] Y2 such that each 4-uple of the form (X1[i], Y1[i], X2[i], Y2[i]) denotes a segment. Return an int representing the number of triangles resulting from the segments' intersection.
Definition
- Class:
- HiddenTriangles
- Method:
- howMany
- Parameters:
- int[], int[], int[], int[]
- Returns:
- int
- Method signature:
- int howMany(int[] X1, int[] Y1, int[] X2, int[] Y2)
- (be sure your method is public)
Constraints
- X1, Y1, X2 and Y2 each contain between 0 and 50 elements, inclusive.
- X1, Y1, X2 and Y2 have the same number of elements.
- All segments must either be parallel to or form a 45 degree angle with one of the axes.
- Each segment has length at least 1.
- All elements are between -100 and 100, inclusive.
Examples
{0,0,0,0,0,3}
{0,0,0,3,3,0}
{3,0,3,3,3,3}
{0,3,3,0,3,3}
Returns: 8
There are four triangles of area 2.25 and another four of area 4.5.
{0,1,0,2,1,2,0,1,2,0,0,0}
{0,0,1,0,0,1,0,0,0,2,1,0}
{2,2,1,0,0,1,0,1,2,2,2,2}
{2,1,2,2,1,2,2,2,2,2,1,0}
Returns: 44
{0,1,2,0,0,0}
{0,0,0,2,1,0}
{0,1,2,2,2,2}
{2,2,2,2,1,0}
Returns: 0
This is a set of perpendicular lines forming a square divided into four smaller squares. No triangles can be made.
{}
{}
{}
{}
Returns: 0
{-50,-40,-30,-20,-10,0,10,20,30,40,50,-100,-100,5,6,7,20}
{0,0,0,0,0,0,0,0,0,0,0,25,75,8,8,8,0}
{-50,-40,-30,-20,-10,0,10,20,30,40,50,100,100,55,56,57,-40}
{100,100,100,100,100,100,100,100,100,100,100,25,75,58,58,58,60}
Returns: 31
{0,1,2,2,1,0}
{0,1,0,0,1,0}
{1,2,0,0,2,1}
{1,0,0,0,0,1}
Returns: 1
{0,1,0,1,2}
{0,1,0,1,2}
{2,3,2,2,2}
{2,3,0,0,0}
Returns: 3
{-100,-84,-68,-52,-36,-20,-4,12,28,44,60,76,92,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-99,-98,-97,-96,-95,-94,-93,-92,-91,-90,-89,-100,99,98,97,96,95,94,93,92,91,90,89,100}
{-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-84,-68,-52,-36,-20,-4,12,28,44,60,76,92,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-99,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-99}
{-100,-84,-68,-52,-36,-20,-4,12,28,44,60,76,92,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,99,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-99}
{100,100,100,100,100,100,100,100,100,100,100,100,100,-100,-84,-68,-52,-36,-20,-4,12,28,44,60,76,92,99,98,97,96,95,94,93,92,91,90,89,100,99,98,97,96,95,94,93,92,91,90,89,100}
Returns: 7227
{-100,-84,-68,-52,-36,-20,-4,12,28,44,60,76,92,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-95,-90,-85,-80,-75,-70,-65,-60,-55,-50,-45,-100,95,90,85,80,75,70,65,60,55,50,45,100}
{-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-84,-68,-52,-36,-20,-4,12,28,44,60,76,92,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-95,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-95}
{-100,-84,-68,-52,-36,-20,-4,12,28,44,60,76,92,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,95,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-95}
{100,100,100,100,100,100,100,100,100,100,100,100,100,-100,-84,-68,-52,-36,-20,-4,12,28,44,60,76,92,95,90,85,80,75,70,65,60,55,50,45,100,95,90,85,80,75,70,65,60,55,50,45,100}
Returns: 5825
{1,1,5,2,2,7,7}
{1,1,5,2,2,0,5}
{8,9,7,7,7,7,7}
{8,9,7,7,2,5,10}
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-26,-28,-28,-28,-25,-30,-25,-25,-28}
{-25,-26,-30,-27,-30,-28,-30,-27,-27,-23,-26,-29,-30,-24,-23,-26,-24,-30,-30,-24,-30,-25,-30,-30,-24,-24,-28,-27,-29,-25,-25,-30,-27,-27,-27,-30,-27,-23,-26,-26,-26,-25,-27,-25,-24,-27,-23,-26,-28,-26}
{-23,-32,-26,-26,-25,-24,-28,-24,-24,-23,-23,-32,-25,-29,-23,-27,-29,-30,-30,-26,-25,-21,-21,-28,-31,-32,-29,-28,-21,-27,-34,-30,-29,-23,-26,-28,-21,-24,-26,-23,-25,-25,-29,-25,-30,-25,-26,-25,-25,-28}
{-23,-26,-33,-27,-30,-25,-29,-32,-29,-24,-22,-34,-31,-25,-27,-27,-20,-35,-25,-29,-33,-30,-30,-25,-24,-24,-31,-31,-29,-26,-30,-27,-31,-27,-24,-30,-23,-27,-27,-29,-26,-24,-27,-22,-24,-24,-19,-28,-24,-27}
Returns: 50
{5,4,0,4,3,5,5,1,1,0}
{5,5,0,4,4,4,5,2,1,0}
{0,9,3,6,3,-1,11,5,-3,0}
{10,0,0,6,-2,-2,5,-2,-3,2}
Returns: 3
{-24,25,7,-3,-25,-2,-3,-28,4,15,-23,-25,3,-15,4,7,1,16,2,-19,20,-7,-2,-5,20,18,-25,-16,-13,8,-1,18,-20,-1,6,3,7,-3,-21,-18,6,-6,-27,-2,8,4,11,14,1,24}
{14,0,-30,-16,10,-26,-6,-6,9,2,5,-17,-18,17,27,-30,5,22,2,-30,-13,-4,18,-28,29,-13,9,-29,28,20,20,-2,9,-23,14,3,-27,21,-17,-29,-23,-9,10,10,10,16,-28,-5,-15,3}
{-24,-11,-42,-30,-82,-59,55,19,51,66,-78,-25,56,-72,4,-36,-37,-30,2,-19,-21,-7,48,-5,-21,-13,34,-67,-13,-20,-54,53,11,59,-52,-46,48,-34,21,-49,6,56,36,59,44,-30,-46,76,49,-21}
{74,36,19,-16,10,-26,52,-6,-38,-49,5,11,-71,17,68,-73,43,-24,-24,30,-54,38,68,-53,70,-44,-50,-80,-9,20,-33,-2,-22,37,14,-46,-68,-10,-59,2,35,-71,73,-51,46,50,-28,-5,33,3}
Returns: 229
{-2,-6,-9,14,-8,-15,-11,1,-5,2,-10,10,14,27,25,-7,27,-6,21,4,16,-2,-21,19,-4,-6,3,21,28,-18,-30,-11,27,-1,-11,16,-7,26,18,-12,15,-27,10,22,1,-1,21,-21,-19,-29}
{-27,15,-18,12,-27,4,12,3,9,-8,-10,4,-30,-17,10,21,-11,-29,-11,-20,-4,16,-20,-28,-29,-16,-28,28,16,-21,25,7,14,3,6,-20,-11,1,22,-1,-29,1,-25,13,-17,-15,-2,23,5,29}
{62,19,55,52,35,25,19,39,37,61,35,74,71,67,60,20,64,29,73,46,74,24,41,70,43,42,40,55,84,18,9,19,77,25,45,58,43,82,47,32,44,30,55,78,56,27,72,32,36,32}
{-91,-10,-18,50,-27,44,-18,41,51,-67,-10,4,-87,-17,-25,-6,-48,-29,-11,-62,-62,16,42,23,-76,-64,-28,62,16,-57,-14,7,64,3,6,22,39,1,22,43,-29,-56,-25,-43,-72,-43,-53,23,60,29}
Returns: 74
{4,0,4,2,4,1,4,1,0,2,4,1,2,4,2,1,2,0,0,2,4,4,3,1,2,3,3,4,1,3,4,0,1,3,1,0,0,1,1,3,2,3,2,0,0,0,1,2,2,1}
{3,4,2,1,1,0,3,1,3,4,4,0,3,0,0,1,4,1,0,0,2,4,2,2,2,4,3,2,1,1,1,0,3,3,4,1,4,2,0,4,2,2,0,3,3,3,0,3,2,4}
{4,0,4,5,2,4,2,1,-1,1,7,1,3,3,1,-2,3,-3,-1,2,6,5,4,0,4,3,6,5,1,4,1,-2,-2,3,1,-2,-1,-2,-1,3,1,6,3,0,-3,-1,-2,3,2,1}
{1,3,5,-2,1,0,3,-2,4,3,1,2,4,1,-1,-2,3,1,-1,3,0,3,1,2,0,7,0,1,-2,2,-2,-2,0,1,7,-1,5,2,0,6,1,2,0,5,3,3,0,2,4,1}
Returns: 32
{-8,-8,-6,-9,-7,-10,-6,-7,-10,-9,-7,-10,-9,-10,-7,-7,-9,-6,-8,-6,-6,-7,-6,-10,-8,-9,-6,-10,-7,-7,-6,-10,-10,-9,-7,-9,-10,-10,-10,-9,-6,-10,-7,-9,-9,-9,-6,-8,-7,-10}
{-6,-7,-6,-10,-7,-7,-9,-6,-9,-9,-6,-6,-8,-9,-10,-9,-10,-10,-7,-10,-9,-6,-9,-10,-9,-10,-6,-6,-9,-7,-8,-9,-7,-10,-10,-9,-7,-8,-6,-8,-7,-7,-8,-6,-9,-7,-9,-6,-8,-6}
{-12,-11,-3,-13,-16,-10,2,-14,-8,-11,-1,-3,-15,-19,-4,-15,-12,-11,-16,0,0,-7,-5,-10,-8,-9,-6,-10,-7,-7,1,-11,-6,-8,-11,-14,-10,-17,-17,-6,-6,-10,-7,-6,-5,-9,-8,-15,-12,-15}
{-2,-4,-9,-14,-16,-3,-9,-13,-7,-9,-12,1,-8,-9,-10,-17,-7,-10,1,-10,-15,-1,-9,-4,-3,-18,-3,1,-12,-11,-8,-8,-11,-9,-10,-4,0,-8,-13,-11,-4,-4,1,-3,-5,-10,-9,1,-8,-1}
Returns: 80
{73,74,71,73,73,74,74,73,72,74,72,70,73,74,73,70,72,72,71,74,73,74,72,72,72,71,74,72,73,74,73,70,71,71,71,74,70,74,70,72,74,73,74,73,71,73,72,72,71,70}
{-9,-9,-6,-8,-10,-9,-6,-10,-7,-7,-10,-10,-7,-10,-7,-9,-7,-10,-6,-10,-8,-10,-10,-9,-9,-10,-7,-9,-6,-7,-10,-6,-10,-6,-7,-8,-10,-6,-8,-7,-10,-10,-7,-6,-10,-8,-6,-7,-6,-6}
{66,66,78,68,82,74,74,83,67,74,79,65,78,80,67,70,78,63,71,68,73,74,63,72,72,76,74,64,80,64,73,77,71,78,62,84,60,66,70,81,81,79,67,73,62,82,62,63,62,62}
{-9,-17,-6,-8,-10,-2,2,-10,-2,2,-17,-5,-12,-10,-13,-16,-7,-10,4,-10,-14,-4,-19,1,0,-5,-13,-9,1,-17,-5,1,-2,-6,2,2,-10,-6,-3,-7,-10,-10,0,2,-10,1,-6,-16,3,-14}
Returns: 97
{26,20,26,26,26,29,17,13,30,34,32,28,30,10,29,16,17,13,20,33,25,20,33,19,32,17,22,29,18,11,32,14,20,23,28,23,31,30,11,27,15,30,27,10,15,22,21,25,26,32}
{-7,11,14,-5,4,0,14,-1,12,12,-5,9,7,-7,7,6,9,-1,11,13,-1,4,-4,14,7,-8,-6,9,-4,-8,12,0,14,-9,-4,1,14,13,0,-4,-10,12,8,12,12,3,-2,4,-5,1}
{26,20,26,78,-33,-24,35,-44,60,-4,-1,-11,30,-40,29,-27,63,13,74,50,-19,60,-6,58,32,17,22,-36,40,-43,78,-31,0,-6,-18,87,-36,67,54,97,41,73,-14,-60,83,58,42,25,-14,54}
{-37,46,34,-57,63,53,-4,56,-18,12,28,-30,76,43,-31,-37,-37,30,-43,30,-45,-36,-4,-25,76,36,24,9,18,-8,58,45,34,20,-50,65,14,13,43,66,-10,-31,8,12,12,3,19,30,-5,23}
Returns: 325
{7,16,14,17,14,17,23,20,4,12,16,2,6,7,6,0,2,16,5,21,10,9,19,20,24,5,15,13,9,19,7,9,24,22,10,3,14,15,3,18,12,0,17,5,9,5,21,6,18,19}
{16,24,13,11,3,9,15,22,11,15,16,17,5,1,15,18,13,14,6,20,3,12,12,15,6,2,20,17,9,1,15,10,10,9,24,3,21,18,1,24,15,2,10,7,1,22,0,15,4,3}
{58,88,14,-37,83,-34,73,89,-49,78,16,2,-54,-55,-45,0,-59,16,68,-42,-60,9,-49,-37,24,-65,-40,74,77,-49,72,-42,24,-37,75,67,-44,77,3,-50,62,0,-35,5,9,-46,87,6,71,-52}
{67,24,70,65,72,9,65,91,11,15,-39,-50,-55,-61,15,-54,-48,64,-57,20,73,62,12,15,-57,72,20,-44,-59,69,80,-41,-51,-50,89,3,-37,-44,59,24,65,72,-42,62,-56,73,66,-54,57,3}
Returns: 319
{3,4,9,9,6,6,0,4,9,3,2,5,3,8,4,3,3,0,8,5,8,7,8,7,1,0,8,8,0,5,6,4,9,6,3,0,1,6,1,6,4,7,0,9,7,5,1,8,9,4}
{0,3,1,3,9,0,5,9,9,2,5,1,0,4,7,3,2,5,2,7,3,2,9,4,0,9,8,6,7,4,4,6,3,1,8,5,8,9,3,2,2,5,0,9,5,6,0,3,6,9}
{4,4,8,9,7,6,0,3,10,2,1,6,2,9,3,4,2,1,8,6,9,7,9,8,0,1,7,7,-1,5,6,4,10,7,2,-1,1,5,2,7,3,6,0,8,6,6,0,9,10,5}
{1,4,2,2,8,1,4,9,9,1,4,2,1,3,7,4,3,5,3,8,4,1,10,5,0,10,7,6,8,5,5,7,3,1,8,4,9,9,2,3,3,6,-1,9,6,7,0,3,6,10}
Returns: 1
{-68,-70,-72,-67,-69,-67,-68,-69,-67,-72,-67,-69,-72,-68,-71,-67,-69,-71,-69,-69,-70,-67,-69,-68,-69,-68,-71,-69,-71,-69,-72,-68,-72,-67,-67,-69,-67,-67,-68,-68,-71,-68,-72,-71,-71,-68,-72,-67,-70,-70}
{83,82,80,80,80,80,82,82,82,81,83,83,80,83,82,83,81,81,82,82,80,80,82,80,80,81,80,83,80,81,83,82,82,83,82,83,83,82,80,83,83,83,81,81,81,82,82,80,81,83}
{-69,-69,-73,-66,-70,-66,-69,-68,-67,-71,-67,-68,-71,-67,-70,-68,-70,-72,-69,-68,-69,-67,-68,-67,-68,-67,-70,-69,-71,-68,-71,-67,-73,-68,-67,-68,-66,-66,-67,-68,-71,-67,-72,-71,-70,-69,-73,-66,-70,-69}
{84,83,81,81,79,79,82,82,83,80,82,84,81,84,81,84,82,82,81,83,81,79,82,81,81,81,79,82,79,80,83,83,83,84,83,82,82,82,80,82,84,84,82,82,81,83,81,81,80,82}
Returns: 9
{-12,30,-5,23,9,-19,9,-19,2,2,-5,-33,2,-33,2,-26,9,9,23,23,2,-33,-26,-5,-12,-26,-33,-19,-19,9,-19,23,-5,-19,-12,-12,9,-5,23,30,30,23,9,-19,2,-19,-26,-5,-33,-5}
{-23,31,-14,22,4,-32,4,-32,-5,-5,-14,-50,-5,-50,-5,-41,4,4,22,22,-5,-50,-41,-14,-23,-41,-50,-32,-32,4,-32,22,-14,-32,-23,-23,4,-14,22,31,31,22,4,-32,-5,-32,-41,-14,-50,-14}
{-12,72,-54,-26,52,-19,49,21,47,43,-5,-79,2,14,2,16,49,-39,-18,-22,2,9,-26,-50,35,14,8,25,-63,-39,-66,23,-49,21,28,29,9,-5,72,30,71,23,9,-19,-44,28,-26,-5,-33,-53}
{18,31,35,-27,-39,13,-36,8,40,-5,-59,-96,37,-50,-49,1,44,52,63,22,36,-8,3,-59,-70,-81,-91,-32,-76,52,15,-20,-14,8,-23,-23,50,32,-27,78,31,-24,-37,-72,-5,-32,-87,32,-5,-14}
Returns: 137
{-100}
{-100}
{100}
{100}
Returns: 0
{30,50}
{40,60}
{50,70}
{60,80}
Returns: 0
{0, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }
{0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
{10, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }
{0, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Returns: 1