Given a square with N points on each side of the square and none of these points co-incide with the corners of the square. The task is to calculate the total number of triangles that can be formed using these 4 * N points (N points on each side of the square) as vertices of the triangle.
Input: N = 1
There is one point on each side. So we can make three rectangles by leaving one point and picking other three points out of the four.
Input: N = 2
Approach: The number of ways of choosing 3 points among 4 * N points is (4 * N)C3. However, some of them do not form a triangle. This happens when all the three chosen points are on the same side of the square. The count of these triplets is NC3 for each of the side i.e. 4 * NC3 in total. Therefore, the required count of triangles will be ((4 * N)C3) – (4 * NC3).
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Number of triangles that can be formed with given N points
- Count of triangles with total n points with m collinear
- Number of triangles in a plane if no more than two points are collinear
- Number of triangles formed from a set of points on three lines
- How to check if given four points form a square
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Forming smallest array with given constraints
- Steps required to visit M points in order on a circular ring of N points
- Minimum number of points to be removed to get remaining points on one side of axis
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Prime points (Points that split a number into two primes)
- Ways to choose three points with distance between the most distant points <= L
- Number of Integral Points between Two Points
- Check if a number is perfect square without finding square root
- Smallest N digit number whose sum of square of digits is a Perfect Square
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.