精品项目

2017a.t

2025-06-24 1

Based on the filename "2017a.t" and common programming competition contexts, this is likely Problem A from the 2017 ICPC Asia Tsukuba Regional Contest. The problem involves calculating the area of a right-angled triangle where the input consists of Pythagorean triples.

Problem Statement

Given three integers \\(a\\), \\(b\\), and \\(c\\) representing the sides of a right-angled triangle (guaranteed to be a Pythagorean triple, i.e., \\(a^2 + b^2 = c^2\\) where \\(c\\) is the hypotenuse), compute the area of the triangle. The inputs may be in any order.

Input:

2017a.t
  • Multiple test cases, each containing three space-separated integers \\(a\\), \\(b\\), \\(c\\) (\\(1 \\leq a, b, c \\leq 1000\\)).
  • Input ends at EOF.
  • Output:

  • For each test case, output the area (as an integer) on a separate line.
  • Solution Approach

    1. Identify the Hypotenuse: The hypotenuse is the largest side in a right-angled triangle.

    2. Calculate Area: The area is half the product of the two legs (non-hypotenuse sides). Since the inputs form a Pythagorean triple, the product of the legs is always even, ensuring integer area.

    Solution Code

    python

    import sys

    def main:

    data = sys.stdin.read.split

    if not data:

    return

    index = 0

    results = []

    while index < len(data):

    a = int(data[index])

    b = int(data[index + 1])

    c = int(data[index + 2])

    index += 3

    sides = sorted([a, b, c])

    area = sides[0] * sides[1] // 2

    results.append(str(area))

    print('\

    '.join(results))

    if __name__ == "__main__":

    main

    Explanation

    1. Reading Input: The input is read all at once for efficiency, especially given potential multiple test cases.

    2. Processing Each Test Case: For every triplet of integers:

    菲律宾沙龙国际s36金年会
  • Sort the sides to easily access the two legs (smallest values) and the hypotenuse (largest value).
  • Compute the area as \\(\\frac{{\

    ext{{leg}_1 \

    imes \

    ext{{leg}_2}}}}{2}\\), using integer division (since the product is always even).
  • 3. Output: Results for all test cases are collected and printed at once (one per line).

    Example

    Input:

    3 4 5

    5 12 13

    6 8 10

    Output:

    30

    24

    This solution efficiently handles multiple test cases and leverages sorting to identify the legs of the triangle, ensuring correctness for any input order.