본문 바로가기

알고리즘 문제65

백준 2805 나무자르기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import sys input = sys.stdin.readline n,m = map(int, input().split()) li = list(map(int,input().split())) start = 0 end = max(li) result = 0 while start mid: num += i-mid if num 2020. 10. 25.
백준 10816 숫자카드 2 1 2 3 4 5 6 7 8 9 from collections import Counter import sys input = sys.stdin.readline n = int(input()) s = list(map(int, input().split())) m = int(input()) s_ = list(map(int, input().split())) s = Counter(s) for i in s_: print(s[i], end=" ") cs 2020. 10. 25.
1920 수찾기(이분탐색) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import sys input = sys.stdin.readline n = int(input()) s = list(map(int, input().split())) m = int(input()) s_ = list(map(int, input().split())) def bi_search(arr,target,start,end): if start > end : return 0 mid = (start+end) // 2 if target == arr[mid]: return 1 elif target arr[mid]: return bi_search(arr,target,mid+1,end) s.sort() for i in.. 2020. 10. 25.
백준 1655 가운데를 말해요 # 시간 초과뜸 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import heapq import sys n = int(sys.stdin.readline()) a = [int(sys.stdin.readline()) for _ in range(n)] arr = [] q = [] for i in a: start = 0 end = len(arr) mid = (start+end)//2 # 항상 작은수여서 +1 안해도 될듯 arr.append(i) arr.sort() heapq.heappush(q,arr[mid]) for i in q: print(i) Colored by Color Scripter cs # 시간 초과안뜸 heapq 빼고 bisect 씀 1 2 3 4 5 6 7 8 9 .. 2020. 10. 25.
백준 11279 최대힙 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import heapq import sys n = int(sys.stdin.readline()) a = [int(sys.stdin.readline()) for _ in range(n)] q = [] for i in a: if i == 0: if q: print(-heapq.heappop(q)) else: print(0) else : heapq.heappush(q, -i) cs 2020. 10. 25.
백준 11866 요세푸스 문제 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 from collections import deque n, k = map(int, input().split()) queue = deque() li = [] for i in range(n): queue.append(i + 1) print('') cs 2020. 10. 25.