백준/백준 파이썬

백준 파이썬 Today I Learn 2023.06.29

군청레프 2023. 7. 1. 06:40
728x90

6/ 29 파이썬 공부
1. 백준 26592 Triangle Height
Your Math teacher asked you to write a program to help him generate homework solutions. 
The program will need to find the height of a triangle given its area and its base length.

Formula:
a = (h*b)/2 (a – area, b – base length, h – height)

The first line will contain a single integer n that indicates the number of lines that follow. Each line will include the area and base length of a triangle with the two values separated by a single space.

area base

For each input display the height of the triangle with 2 decimal places, in the following format:

The height of the triangle is #.## units

>>>해석
수학 선생님이 숙제 해설을 생성하는 데 도움이 되는 프로그램을 작성하라고 요청했습니다.
프로그램은 삼각형의 넓이와 밑변 길이가 주어진 삼각형의 높이를 찾아야 합니다.

공식:
a = (h*b)/2 (a – 면적, b – 밑면 길이, h – 높이)

첫 번째 줄에는 테스트 케이스의 개수 n이 입력됩니다. 
각 선에는 하나의 공백으로 구분된 두 값이 있는 삼각형의 면적과 기본 길이가 포함됩니다.

면적 밑면 길이

각 입력에 대해 다음 형식으로 소수점 이하 2자리까지 삼각형의 높이를 표시합니다.

The height of the triangle is #.## units

>>>코드

for _ in range(int(input())):
    a, b = map(float, input().split())
    print('The height of the triangle is %.2f units' %(2*a/b))



2. 백준 26340 Fold the Paper Nicely
Dr. Orooji has a daily calendar (365 pages) on his desk. Every morning, he tears off one page and, as he is reading the notes on the next page, he folds (out of habit) the sheet in his hand. Dr. O noticed that he always folds the sheet (a rectangular paper) along the longer side, e.g., if one side is 80 and the other side is 60, he would fold along 80; this will make the paper of size 40 and 60; if he folds it again, he would fold along 60 since that’s the longer side now.

Given a rectangular piece of paper and how many times Dr. O folds it, you are to determine the final sizes. When folding a side with an odd length, the fraction is ignored after folding, e.g., if a side is 7, it will become 3 after folding.

The first input line contains a positive integer, n, indicating the number of data sets. The sets are on the following n input lines, one set per line. Each set contains three positive integers (each ≤ 10000), the first two providing the rectangle sides and the third providing the number of folds.

At the beginning of each test case, output “Data set: v” where v is the input values. Then, on the next output line, print the final values for the rectangle (larger side of the final values first). Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output.

>>>해석
Orooji 박사의 책상에는 일력(365페이지)이 있습니다. 매일 아침 Orooji 박사는 일력을 한 페이지 찢고 다음 페이지에 써둔 메모를 읽으면서 찢은 페이지를 접는 습관이 있습니다. Orooji 박사는 자신이 항상 긴 쪽을 따라 직사각형으로 찢은 일력을 접는다는 것을 알아차렸습니다. 예를 들어, 한 변이 80이고 다른 변이 60이라면 80인 변을 접어 접은 이후 종이의 크기는 40과 60이 될 것입니다. 
한 번 더 접게 된다면 더 긴 변이 된 60인 부분을 따라 접을 것입니다.
직사각형의 종이 조각과 Orooji 박사가 접는 횟수가 주어지면 접은 후의 최종 크기를 구해야 합니다. 
홀수 길이의 변을 접게 된다면 소수부는 무시됩니다. 
예를 들어 길이가 7인 변을 따라 접는다면 접은 후의 길이는 3이 됩니다.

첫째 줄에는 테스트 케이스의 개수가 양의 정수 n으로 주어집니다. 각각의 테스트 케이스는 n개의 줄에 걸쳐 주어지며, 한 줄에 하나의 테스트 케이스가 주어집니다.
각 줄에는 3개의 양의 정수 (각각≤ 10000)가 포함되며, 처음 두 정수는 직사각형의 각 변의 길이, 세번째 정수는 접는 횟수를 나타냅니다.

각 테스트 케이스는 "Data set: v"로 시작합니다. 여기서 v는 테스트 케이스의 입력값입니다.
그 다음줄에 사각형의 두 변의 길이를 길이가  긴 것부터 순서대로 출력합니다. 
각 테스트케이스가 끝나면 빈 출을 출력합니다. 예제 출력과 동일한 형식으로 출력해야합니다.
길이는 항상 정수의 형태이다.

>>>코드

for _ in range(int(input())):
    l = list(map(int, input().split()))
    e1, e2 = l[0], l[1]
    for i in range(l[2]):
        if e1>e2:
            e1 = e1//2
        else:
            e2 = e2//2
    print('Data set:', *l)
    print('%d %d\n' %(max(e1, e2), min(e1, e2)))



3. 백준 25895 Majestic 10
The movie “Magnificent 7” has become a western classic. Well, this year we have 10 coaches training the UCF programming teams and once you meet them, you’ll realize why they are called the “Majestic 10”! The number 10 is actually special in many different ways. For example, in basketball, they keep track of various statistics (points scored, rebounds, etc.) and if a player has 10+ (10 or more) in a particular stat, they call it a double.
Given three stats for a basketball player, you are to determine how many doubles the player has, i.e., how many of the stats are greater than or equal to 10.

The first input line contains a positive integer, n, indicating the number of players. Each of the following n input lines contains three integers (separated by a space and each between 0 and 100, inclusive), providing the three stats for a player.

Print each input line as it appears in the input. Then, on the following output line, print a message indicating how many stats are greater than or equal to 10:

- print zilch if none of the three stats is greater than or equal to 10,
- print double if one of the three stats is greater than or equal to 10,
- print double-double if two of the three stats are greater than or equal to 10,
- print triple-double if all three stats are greater than or equal to 10.

Leave a blank line after the output for each player.

>>>해석
영화 '매그니피센트 7'은 서부극의 고전이 됐다. 
올해 우리에게는 UCF 프로그래밍 팀을 훈련하는 10명의 코치가 있습니다. 
일단 그들을 만나보면 그들이 "마제스틱 10"이라고 불리는 이유를 알게 될 것입니다! 
숫자 10은 사실 여러 면에서 특별합니다. 예를 들어, 농구에서는 다양한 통계(득점, 리바운드 등)를 추적하고 특정 통계에서 선수가 10+(10 이상)이면 이를 더블이라고 부릅니다.

농구 선수에 대한 세 가지 통계가 주어지면 플레이어가 얼마나 많은 더블을 가지고 있는지, 즉 얼마나 많은 통계가 10보다 크거나 같은지 결정해야 합니다.

첫째 줄에 플레이어 수를 나타내는 양의 정수 n이 주어집니다. 다음 n개의 줄에 플레이어에 대한 세 가지 통계를 제공하는 0 이상 100 이하의 세 개의 정수가 공백으로 구분되어 주어집니다.

우선 입력에 주어지는 통계를 출력합니다. 그 후, 더블에 대한 메시지를 출력합니다.

- 세 통계 중 어느 것도 10보다 크거나 같지 않으면 zilch를 출력
- 세 통계 중 하나가 10보다 크거나 같으면 double을 출력
- 세 통계 중 두 통계가 10보다 크거나 같으면 double-double을 출력
- 세 통계가 모두 10보다 크거나 같으면 triple-double을 출력

각 플레이어의 출력 뒤에 빈 줄을 출력합니다.

>>>코드

for _ in range(int(input())):
    l = list(map(int, input().split()))
    r = 0
    for i in l:
        if i >= 10:
            r += 1
    print(*l)
    if r == 0:
        print('zilch\n')
    elif r == 1:
        print('double\n')
    elif r == 2:
        print('double-double\n')
    else:
        print('triple-double\n')
728x90