Programming [Python] (411) 썸네일형 리스트형 #82 백준 파이썬 [7568] 덩치 - 부르트포스 https://www.acmicpc.net/problem/7568 #Solution - 부르트포스(완전 탐색) 기수 정렬(Radix Sort)로 시도해보다가, 기수 정렬은 기수간 우선순위가 있기에 본 문제와는 적합하지 않다는 것을 알았다. 다시 말해 이 문제는 그냥 자기보다 크고 무거운(둘 다 큰) 사람이 몇 명인지 쟤서 자기 등수만 정하면 된다. n명을 n-1번씩 전수 비교해보면 된다. num_student = int(input()) student_list = [] for _ in range(num_student): weight, height = map(int, input().split()) student_list.append((weight, height)) for i in student_list: r.. #81 백준 파이썬 [10989] 수 정렬하기 3 https://www.acmicpc.net/problem/10989 #Solution 메모리 제한으로 인해 모든 수를 받고 정렬하지 못한다. 따라서 미리 10,000이 들어갈 수 있는 리스트를 만들어준 뒤 하나씩 더해주고 메모리에서 없애버리는 방식을 선택해야한다. import sys case = int(input()) result = [0 for i in range(10001)] for num in sys.stdin: result[int(num)] += 1 for i in range(10001): if result[i] > 0: for j in range(result[i]): print(i) #80 백준 파이썬 [11719] 그대로 출력하기 2 https://www.acmicpc.net/problem/11719 #Solution while True: try: print(input()) except EOFError: break #79 백준 파이썬 [9012] 괄호 - 스택 https://www.acmicpc.net/problem/9012 #Solution '('와 ')'를 넣는 스택을 따로 만들어주는 문제이다. 최상단을 Pop해서 '('가 나오지 않으면 NO, 스택이 비지 않아도 NO 처리를 해준다. case = int(input()) result = [] for i in range(case): bracket = list(input()) bracket_stack = [] double_break = True for j in range(len(bracket)): if bracket[j] == "(": bracket_stack.append(bracket[j]) else: try: if bracket_stack.pop() == "(": pass except: result.appe.. #78 백준 파이썬 [2252] 줄 세우기 - 위상정렬 https://www.acmicpc.net/problem/2252 #Solution 해당 문제는 '사이클'이 없고 '방향'만 존재하는 그래프(DAG: Directed Acyclic Graph)에서 정점(Vertex)을 나열하는 방법으로 풀 수 있다. 이를 위상정렬 (Topological Sort)이라고 한다. 0) 정점과 연결된 다른 정점 리스트, 정점에 들어오는 그래프 개수 리스트 2개를 만들어준다. 1) 진입 루트(Indegree)가 없는 정점을 먼저 큐에 넣고 2) 해당 정점과 연결되어있는 노드에서 진입 루트 개수를 하나씩 빼준다. 3) 큐 앞에서부터 출력하고 제거한다. 다시 1)로 돌아가고 큐가 빌 때까지 반복한다. num_student, num_compare = map(int, input().s.. #77 백준 파이썬 [2231] 분해합 https://www.acmicpc.net/problem/2231 #Solution num = int(input()) answer = 0 for i in range(1, num+1): coef_num_list = list(map(int, str(i))) answer = i + sum(coef_num_list) if answer == num: print(i) break if i == num: print(0) #76 백준 알고리즘 [11047] 동전 0 https://www.acmicpc.net/problem/11047 #Solution coin_num, target_money = map(int, input().split()) coin_list = [] total_coin = 0 for i in range(coin_num): coin_list.append(int(input())) for i in range(1, coin_num+1): if target_money // coin_list[-i] > 0: total_coin += target_money // coin_list[-i] target_money = target_money % coin_list[-i] if target_money == 0: break print(total_coin) #75 백준 파이썬 [11718] 그대로 출력하기 https://www.acmicpc.net/problem/11718 #Solution while True: try: print(input()) except EOFError: break 이전 1 ··· 39 40 41 42 43 44 45 ··· 52 다음