Minimum Height Triangle

Given integers b and a, find the smallest integer h, such that there exists a triangle of height h, base b, having an area of at least a.

Example:

Input: base = 17, area = 100
Output: 12

Approach

C++

#include <bits/stdc++.h>

using namespace std;

int lowestTriangle(int baseint area)
{
    if ((area * 2) % base == 0)
        return area * 2 / base;
    return area * 2 / base + 1;
}

int main()
{
    int base = 17;
    int area = 100;
    int height = lowestTriangle(basearea);
    cout << height << "\n";
    return 0;
}


No comments:

Post a Comment