📜  使用两个梯子找到最大无法到达的高度

📅  最后修改于: 2021-06-26 00:34:23             🧑  作者: Mango

给定两个高度为h1h2的梯子。任务是找到两个梯子无法通过任何可能的组合达到的最大高度。如果可以达到所有高度,则打印0
例子:

方法:对于给定的数字ab ,最大数c不可能使ax + by = c ,其中x≥0并且y≥0是等于(a * b)– a – b的弗罗贝尼斯数。
下面是上述方法的实现:

CPP
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to return the maximum height
// which can't be reached
int maxHeight(int h1, int h2)
{
    return ((h1 * h2) - h1 - h2);
}
 
// Driver code
int main()
{
    int h1 = 7, h2 = 5;
 
    cout << max(0, maxHeight(h1, h2));
 
    return 0;
}


Java
// Java implementation of the approach
class GFG
{
 
    // Function to return the maximum height
    // which can't be reached
    static int maxHeight(int h1, int h2)
    {
        return ((h1 * h2) - h1 - h2);
    }
     
    // Driver code
    public static void main(String args[])
    {
        int h1 = 7, h2 = 5;
     
        System.out.println(Math.max(0, maxHeight(h1, h2)));
    }
}
 
// This code is contributed by AnkitRai01


Python
# Python3 implementation of the approach
 
# Function to return the maximum height
# which can't be reached
def maxHeight(h1, h2):
    return ((h1 * h2) - h1 - h2)
 
# Driver code
h1 = 7
h2 = 5
 
print(max(0, maxHeight(h1, h2)))
 
# This code is contributed by mohit kumar 29


C#
// C# implementation of the approach
using System;
 
class GFG
{
 
    // Function to return the maximum height
    // which can't be reached
    static int maxHeight(int h1, int h2)
    {
        return ((h1 * h2) - h1 - h2);
    }
     
    // Driver code
    public static void Main()
    {
        int h1 = 7, h2 = 5;
     
        Console.WriteLine(Math.Max(0, maxHeight(h1, h2)));
    }
}
 
// This code is contributed by AnkitRai01


Javascript


输出:
23

时间复杂度: O(1)

如果您希望与行业专家一起参加现场课程,请参阅《 Geeks现场课程》和《 Geeks现场课程美国》。