给定高度等腰三角形和两个整数 , 。任务是找到高度从三角形的顶部开始,这样,如果我们从顶部平行于底部在高度h处进行切割,则三角形必须分成两部分,其面积比等于n:m 。
例子:
Input : H = 4, n = 1, m = 1
Output : 2.82843
Input : H = 4, n = 1, m = 0
Output : 4
首先,在继续之前,让我们提及等腰三角形的一些基本属性。
假设▲ABC是等腰三角形,AB = AC,BC是三角形的边和底边不相等。如果D是BC的中点,则AD是我们的高度H。此外,如果我们画一条与BC的平行线,分别在E和F点切开AB和AC,而G是EF的中点,则▲AEG类似于▲ABD,▲AFG类似于▲ACD,▲AEF类似于▲ABC,通过使用相似三角形的属性,我们可以得出以下几点:
AE / AB = AG / AD = EG / BD = EF / BC = AF / AC-(i)
根据问题的要求,我们必须找出高度h,以使▲AEF面积与梯形EFCB面积之比= n:m。
Let, h is the height of cut from the top of the triangle.
Now, area of ▲AEF = 0.5 * AG * EF and area of trapezium EFCB = 0.5 * GD * (EF+BC)
also, ratio of both is n:m.
So, we can say that ratio of area of ▲AEF to area of ▲ABC is equal to n :(n+m).
=> area of ▲AEF / area of ▲ABC = n / (n+m)
=> (0.5 * AG * EF) / (0.5 * AD * BC) = n / (n+m)
=> (AG/AD) * (EF/BC) = n / (n+m)
=> (EF/BC) * (EF/BC) = n / (n+m)
=> h2 /H2 = n / (n+m)
=> h = H*sqrt(n/(n+m))
下面是上述方法的实现:
C++
// C++ program, to find height h
// which divide isosceles triangle
// into ratio n:m
#include
using namespace std;
// Function to return the height
float heightCalculate(int H, int n, int m)
{
// type cast the n, m into float
float N = n * 1.0;
float M = m * 1.0;
// calculate the height for cut
float h = H * sqrt(N / (N + M));
return h;
}
// Driver code
int main()
{
int H = 10, n = 3, m = 4;
cout << heightCalculate(H, n, m);
return 0;
}
Java
// Java program, to find height h
// which divide isosceles triangle
// into ratio n:m
import java.io.*;
class GFG {
// Function to return the height
static float heightCalculate(int H, int n, int m)
{
// type cast the n, m into float
float N = (float)(n * 1.0);
float M = (float)(m * 1.0);
// calculate the height for cut
float h = H *(float) Math.sqrt(N / (N + M));
return h;
}
// Driver code
public static void main (String[] args) {
int H = 10, n = 3, m = 4;
System.out.print( heightCalculate(H, n, m));
}
}
Python3
# Python 3 program, to find height
# h which divide isosceles triangle
# into ratio n:m
from math import sqrt
# Function to return the height
def heightCalculate(H, n, m):
# type cast the n, m into float
N = n * 1.0
M = m * 1.0
# calculate the height for cut
h = H * sqrt(N / (N + M))
return h
# Driver code
if __name__ == '__main__':
H = 10
n = 3
m = 4
print("{0:.6}" .
format(heightCalculate(H, n, m)));
# This code is contributed
# by Surendra_Gangwar
C#
// C# program, to find height h
// which divide isosceles triangle
// into ratio n:m
using System;
class GFG
{
// Function to return the height
static float heightCalculate(int H,
int n, int m)
{
// type cast the n, m into float
float N = (float)(n * 1.0);
float M = (float)(m * 1.0);
// calculate the height for cut
float h = H * (float) Math.Sqrt(N / (N + M));
return h;
}
// Driver code
public static void Main ()
{
int H = 10, n = 3, m = 4;
Console.WriteLine(heightCalculate(H, n, m));
}
}
// This code is contributed
// by inder_verma
PHP
Javascript
6.54654