Soluție HackerRank pentru Minimum Height Triangle, subdomeniul Fundamentals, în Python 3. Include cerința formatată, exemple, explicația pașilor și cod…

  • Problemă: Minimum Height Triangle
  • Domeniu: Fundamentals
  • Limbaj: Python 3

Challenge: Minimum Height Triangle

Subdomeniu: Fundamentals (fundamentals)

Scor cont: 10.0 / 10

Submission status: Accepted

Submission score: 1.0

Submission ID: 464719755

Limbaj: python3

Link challenge: https://www.hackerrank.com/challenges/lowest-triangle/problem

Cerință

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.

![image](https://s3.amazonaws.com/hr-assets/0/1496306792-f2c37eea44-triangle.jpg)

Example
b = 4
a = 6

The minimum height h is 3. One example is a triangle formed at points (0, 0), (4, 0), (2, 3).

Function Description

Complete the *lowestTriangle* function in the editor below.

*lowestTriangle* has the following parameters:

- *int b:* the base of the triangle
- *int a:* the minimum area of the triangle

Returns

- *int:* the minimum integer height to form a triangle with an area of at least a

Input Format

There are two space-separated integers b and a, on a single line.

Constraints

+ 1 ≤ b ≤ 10^6
+ 1 ≤ a ≤ 10^6

Cod sursă

#!/bin/python3

import math
import os
import random
import re
import sys

def lowestTriangle(trianglebase, area):
        h = 0
        while True:
                temp_area = 0.5*trianglebase*h
                if temp_area >= area:
                        return h
                h+= 1
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    first_multiple_input = input().rstrip().split()

    trianglebase = int(first_multiple_input[0])

    area = int(first_multiple_input[1])

    height = lowestTriangle(trianglebase, area)

    fptr.write(str(height) + '\n')

    fptr.close()
HackerRank Fundamentals – Minimum Height Triangle