본문 바로가기

분류 전체보기

(208)
아이들과 선물상자[백준 23757] https://www.acmicpc.net/problem/23757 파이썬의 우선순위 큐인 heapq 사용하면 쉽게 풀 수 있다. import heapq n,m = map(int, input().split())giftcnt = list(map(int ,input().split()))wantcnt = list(map(int ,input().split()))heap = []for i in giftcnt : heap.append(i*(-1))heapq.heapify(heap)ans = 1 for i in wantcnt : minus_k= heapq.heappop(heap) k = (-1)*minus_k if i > k : print(0) exit() ..
강의실[백준 1374] https://www.acmicpc.net/problem/1374  우선순위 큐를 이용하여 문제 해결이 가능하다. import heapq n=int(input())heap1,heap2 = [],[]ans,flag = 0,0for _ in range(n): a,b,c=map(int,input().split()) heapq.heappush(heap1, (b,c))while heap1 : s,e = heapq.heappop(heap1) if flag ==0 : flag += 1; ans +=1 ;heapq.heappush(heap2, (e,s,1)) else : flag += 1 if heap2[0][0]
Heat Wave[백준 5996] https://www.acmicpc.net/problem/5996 전형적인 최단경로 찾기 문제입니다. import heapq t,c,ts,te =map(int,input().split())gra =[[] for _ in range(t+1)]inf = 1e9 def dijk(start,end): dp=[inf]*(t+1) dp[start] = 0 heap=[] heapq.heappush(heap,(0,start)) while heap: wei,now =heapq.heappop(heap) if wei > dp[now] :continue for nextnode,cost in gra[now]: if dp[nextnode] >..
Road to Savings[백준 27617] https://www.acmicpc.net/problem/27617   최단경로가 되는 경로를 모두 저장하고 전체 경로에서 최단경로에 포함 안 되는 것들을 찾으면 된다. import heapqdef dijkstra(start, n, gra): dp = [float('inf')] * (n + 1) dp[start] = 0 heap = [(0, start)] parent = [[] for _ in range(n + 1)] while heap: wei, now = heapq.heappop(heap) if dp[now]
안정적인 문자열[백준 4889] https://www.acmicpc.net/problem/4889 def count_operations_to_stable(s): stack = [] operations = 0 for char in s: if char == '{': stack.append(char) else: # char == '}' if stack: stack.pop() else: operations += 1 stack.append('{') operations += len(stack) // 2 return operationst..
치킨 TOP N [백준 11582] https://www.acmicpc.net/problem/11582#include #include // 비교 함수 정의 (qsort에 사용)int compare(const void *a, const void *b) { return (*(int*)a - *(int*)b);}int main() { int N, k; scanf("%d", &N); int c[N]; for (int i = 0; i  입력에 따라서 배열을 구간별로 정령해주면 된다.
줄 세우기 [백준 11536] 이름을 입력 받아서 배열에 추가한다. 이후에 배열을 정렬해보고 정렬 전의 배열과 비교해본다.  https://www.acmicpc.net/problem/11536n= int(input())strings = []for _ in range(n): name =str(input().rstrip()) strings.append(name) newstring = strings.copy() strings.sort()if newstring == strings : print('INCREASING')elif newstring[::-1]==strings : print('DECREASING')else : print('NEITHER')# print(newstring)
순회강연 [백준 2109] 처음에 정렬을 날짜말고 가격만 고려해서 정렬하면 된다. 그리고 해당 강연을 최대한 뒤의 날로 정하면 된다. https://www.acmicpc.net/problem/2109 import sysans = [0] * 10001n = int(sys.stdin.readline())data = []for i in range(n): p, d = map(int, sys.stdin.readline().split()) data.append((p, d))data.sort(key= lambda x:-x[0])for p, d in data: while ans[d] != 0: d -= 1 if d != 0: ans[d] = pprint(sum(ans))