Split given isosceles triangle of height H into N equal parts
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, divide the total area into N equal parts.
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
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 triangle such that (xi / h)2 = i / N
=> xi = h*√(i/n)
xi = height of ith cut from the top vertex of the triangle
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)