Given an integer N and an isosceles triangle consisting of height H, the task is to find (N – 1) points on the triangle such that the line passing through these points and parallel to the base of the triangle, divides the total area into N equal parts.
Input: N = 3, H = 2
Output: 1.15 1.63
Explanation: Make cuts at point 1.15 and 1.63 as shown below:
Input: N = 2, H = 1000
Approach: The problem can be solved by observing the following properties:
Divide the trangle such that (xi / h)2 = i / N
=> xi = h*√(i/n)
xi = height of ith cut from the top vertex of the trangle
Follow the steps below to solve the problem:
- Iterate over the range [1, N – 1].
- In every ith iteration, print the value of xi using the above formula.
Below is the implementation of the above approach:
Time Complexity: O(N)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.