본문 바로가기

algorithm87

[백준 10815번] 숫자 카드 1. 이진 탐색을 활용하여 푼 방법 (1856ms) n = int(input()) array_n = sorted(list(map(int,input().split()))) m = int(input()) array_m = list(map(int,input().split())) def binary_search(array,target,start,end): while start target: end = mid - 1 else: start = mid + 1 return 0 for i in array_m: print(binary_search(array_n,i,0,n-1),end=" ") 2. 집합(Set) 자료형을 사용하여 푼 방법 (664ms) n = int(input()) array_n = list(map(int.. 2023. 2. 23.
[백준 10816번] 숫자 카드 2 1. 사전 자료형 + 이진 탐색을 활용하여 푼 방법 (2508ms) import sys input = sys.stdin.readline n = int(input()) array_n = sorted(list(map(int,input().split()))) m = int(input()) array_m =list(map(int,input().split())) dictionary = {} for i in array_n: if i not in dictionary: dictionary[i] = 1 else: dictionary[i] += 1 def binary_search(array,target,start,end): while start 2023. 2. 22.
[백준 2309번] 일곱 난쟁이 from itertools import combinations array = [0]*9 for i in range(9): array[i] = int(input()) remain = sum(array)-100 com_list = list(combinations(array,2)) for i in com_list: if sum(i) == remain: array.remove(i[0]) array.remove(i[1]) break array.sort() for i in array: print(i) 이번 문제는 정렬보다는 9명의 난쟁이 중 키의 합이 100이 되도록 만드는 조건을 구현하는 것이 관건인 문제였다. 문제에서 일곱 난쟁이를 찾을 수 없는 경우는 없다는 조건이 주어졌기 때문에, 무조건 난쟁이 7명이상은 .. 2023. 2. 22.
[백준 11651번] 좌표 정렬하기 2 import sys input = sys.stdin.readline n = int(input()) array = [] for i in range(n): x, y = map(int,input().split()) array.append((x,y)) array.sort(key=lambda x:x[0]) array.sort(key=lambda x:x[1]) for i in array: print(f"{i[0]} {i[1]}") 2023. 2. 21.
[백준 10814번] 나이순 정렬 import sys input = sys.stdin.readline n = int(input()) array = [] for i in range(n): age, name = list(input().split()) array.append((int(age),name,i)) array.sort(key=lambda x:x[2]) array.sort(key=lambda x:x[0]) for i in range(n): print(f"{array[i][0]} {array[i][1]}") 2023. 2. 21.
[백준 11650번] 좌표 정렬하기 n = int(input()) array = [] for i in range(n): x, y = map(int,input().split()) array.append((x,y)) array.sort(key=lambda x:x[1]) array.sort(key=lambda x:x[0]) for i in array: print(f"{i[0]} {i[1]}") 2023. 2. 21.