[백준] 11050, 1966, 2108 (파이썬)

Colacan·2022년 2월 17일
1

[백준]

목록 보기
31/43

오늘은 구현에 대한 문제만 풀었다. 그리디 알고리즘을 풀었어야하는데 문제가 생각보다 시간이 걸려서 건드리지를 못했다. 이러한 경우를 대비해서 앞으로는 그리디 알고리즘 문제부터 풀고 시작해야 할 것 같다.

백준 11050번 이항 계수 1

import sys,math
N,K = map(int,sys.stdin.readline().split())
twohang = math.factorial(N)/(math.factorial(K)*math.factorial(N-K))
print(int(twohang))

백준 1966번 프린터 큐

# 알고리즘 일부 참고하였다.
# 문제에서 표현한 그대로 구현하도록 노력하자
import sys
T = int(sys.stdin.readline())
for i in range(T):
    N,M = map(int,sys.stdin.readline().split())
    imp = list(map(int,sys.stdin.readline().split()))
    imp_lst = [0 for _ in range(N)] 
    imp_lst[M] = 1
    cnt = 0
    while True:
        if imp[0] == max(imp):
            cnt += 1
            if imp_lst[0] != 1:
                del imp[0]
                del imp_lst[0]
            else:
                print(cnt)
                break
        else:
            imp.append(imp[0])
            del imp[0]
            imp_lst.append(imp_lst[0])
            del imp_lst[0]

백준 2108번 통계학

import sys
from collections import Counter
list_num = []
T = int(sys.stdin.readline())
for _ in range(T):
    list_num.append(int(sys.stdin.readline()))
list_num.sort()
mea = round(sum(list_num)/len(list_num))
mid = list_num[len(list_num)//2]
cnt = Counter(list_num).most_common(2)
if len(list_num) > 1:
    if cnt[0][1] == cnt[1][1]:
        bindo_num = cnt[1][0]
    else:
        bindo_num = cnt[0][0]
else:
    bindo_num = cnt[0][0]
road = max(list_num)-min(list_num)
print(mea)
print(mid)
print(bindo_num)
print(road)
profile
For DE, DA / There is no royal road to learning

0개의 댓글