Beecrowd 1045 problem breakdown

Question

Introduction

Beecrowd 1045 – Triangle Types is a difficult task generally popular with the public, which allows those in need of help to understand and illustrate how to do triangle classification based on the given sides’ lengths. The reader might either be solving this problem for competitive programming, while brown-bagging lunch for two weeks during technical interviews, or while playing with scratch in his or her homework, but the logic behind the solution developed is vital.

By the conclusion of this guide, you will comprehend the problem statement and a proposed C, C++, and Python solution highly optimized for speed and memory. In addition, some of the most frequently asked questions about the problem are answered to bolster the readers’ understanding of it. After all, you’ll have a solid understanding of how to attack similar problems efficiently not others.

Beecrowd1045 Problem Breakdown Solution in C

Summary of Triangle Classification

  1. Check if it forms a triangle (Triangle Inequality Theorem).
  2. Determine the type based on angles:
    • Right triangle → a² == b² + c²
    • Obtuse triangle → a² > b² + c²
    • Acute triangle → a² < b² + c²
  3. Determine the type based on side lengths:
    • Equilateral triangle → All sides are equal.
    • Isosceles triangle → Two sides are equal.
    • Scalene triangle → All sides are different (implicitly handled by other checks).

This program ensures that the input is properly analyzed, and it correctly classifies any given set of three side lengths into the appropriate triangle type.

Would you like any modifications or additional explanations? 😊

BEE 1045 – Triangle Types Solution in C++

#include <bits/stdc++.h>
using namespace std;


int main() {
    double a, b, c, temp, i, j;
    cin >> a >> b >> c;

    if (a < b) {
        temp = a;
        a = b;
        b = temp;
    }
    if (a < c) {
        temp = a;
        a = c;//Beecrowd 1045 Triangle Types solution 
        c = temp;
    }
    if (b < c) {
        temp = b;
        b = c;
        c = temp;
    }

    i = b * b + c * c;
    j = a * a;

    if (a >= b + c) {
cout << "NAO FORMA TRIANGULO" <<endl;
    } else {
        if (j == i) {
cout << "TRIANGULO RETANGULO" << endl;
        }
        if (j > i) {
cout << "TRIANGULO OBTUSANGULO" << endl;
        }
        if (j < i) {
cout << "TRIANGULO ACUTANGULO" <<endl;
        }
        if (a == b && b == c) {
cout << "TRIANGULO EQUILATERO" <<endl;
        } else if (a == b || b == c || c == a) {
cout << "TRIANGULO ISOSCELES" <<endl;
        }
    }

    return 0;
}

This C++ program classifies a triangle based on its side lengths. Here’s a concise breakdown:

  1. Input: Reads three sides (a, b, c).
  2. Sorting: Ensures a is the largest using conditional swaps.
  3. Triangle Check: If a ≥ b + c, it’s not a triangle (NAO FORMA TRIANGULO).
  4. Angle Classification:
    • Right triangle (TRIANGULO RETANGULO) if a² == b² + c²
    • Obtuse triangle (TRIANGULO OBTUSANGULO) if a² > b² + c²
    • Acute triangle (TRIANGULO ACUTANGULO) if a² < b² + c²
  5. Side Classification:
    • Equilateral (TRIANGULO EQUILATERO) if all sides are equal.
    • Isosceles (TRIANGULO ISOSCELES) if any two sides are equal.

It efficiently determines and prints the appropriate classification. 🚀

BEE 1045 – Triangle Types Solution in Python

def main():
    a, b, c = map(float, input().split())
    temp = 0
    i = 0
    j = 0

    if a < b:
        temp = a
        a = b
        b = temp
    if a < c:
        temp = a
        a = c
        c = temp
    if b < c:
        temp = b
        b = c
        c = temp

    i = b * b + c * c
    j = a * a

    if a >= b + c:
        print("NAO FORMA TRIANGULO")
    else:
        if j == i:
            print("TRIANGULO RETANGULO")
        if j > i:
            print("TRIANGULO OBTUSANGULO")
        if j < i:
            print("TRIANGULO ACUTANGULO")
        if a == b and b == c:
            print("TRIANGULO EQUILATERO")
        elif a == b or b == c or c == a:
            print("TRIANGULO ISOSCELES")

if __name__ == "__main__":
    main()

Summary

  • The program reads three side lengths.
  • It sorts them in descending order.
  • It checks if a triangle can be formed.
  • It classifies the triangle based on:
    • Angles: Right, Obtuse, or Acute.
    • Sides: Equilateral, Isosceles, or Scalene.

Would you like any modifications or improvements? 🚀

Next problem: Beecrowd 1046 solution || URI – BEECROWD – BEE Online Judge Solution  1046-Game Time

Leave a Comment