백준(Python) 2108, 11651, 11729

오성인·2023년 3월 17일
0

알고리즘

목록 보기
11/18
post-custom-banner

https://www.acmicpc.net/problem/2108

import sys, collections
input = sys.stdin.readline

n = int(input())
num_lst = []
for _ in range(n):
    num_lst.append(int(input()))
num_lst.sort()


# 산술평균
print(round(sum(num_lst) / n))
# 중앙값
print(num_lst[n//2])
# 최빈값
most = collections.Counter(num_lst).most_common(2)
if len(most) > 1 and most[0][1] == most[1][1]:
    print(most[1][0])
else:
    print(most[0][0])
# 범위
print(num_lst[-1]-num_lst[0])

https://www.acmicpc.net/problem/11651

import sys
input = sys.stdin.readline

n = int(input())
lst = []
for _ in range(n):
    lst.append(list(map(int, input().split())))
lst.sort(key=lambda x: (x[1], x[0]))
for x, y in lst:
    print(x, y)

https://www.acmicpc.net/problem/11729

import sys
input = sys.stdin.readline

n = int(input())

#  hanoi(n, start, mid, target):
#   hanoi(n-1, start, target, mid):
#   1에서 타겟 print(start, target)
#   hanoi(n-1  mid start target)
def hanoi(n, start, mid, target):
    if n == 1:
        print(start, target)
        return
    hanoi(n-1, start, target, mid) # n-1까지의 원판을 mid로 이동
    hanoi(1, start, mid, target)
    hanoi(n-1, mid, start, target) # mid에 있는 원판들을 target으로 이동

print(2**n-1)
hanoi(n, 1, 2, 3)
profile
기여하는 개발자
post-custom-banner

0개의 댓글