-
걍 다익스트라 사용
11256번: 사탕
당신은 사탕 공장의 주인이다. 날마다, 당신은 J개의 사탕을 가게에 보내기 위해 상자에 포장해야 한다. 당신은 크기가 다른 상자 N개를 가지고 있다. 당신은 편리를 위해 상자를 최소한으로 쓰
www.acmicpc.net
한번쓰니께 편함
import sys input = sys.stdin.readline import heapq t=int(input()) while t!=0: t-=1 j,n=map(int,input().split()) #사탕, 상자 list=[] for _ in range(n): r, c =map(int,input().split()) heapq.heappush(list, -r*c) ans=0 while j>0: if ans>=n: break a=heapq.heappop(list) j+=a ans+=1 #if j>0: print() print(ans)
20937번: 떡국
Naver D2를 아시나요? D2는 For Developers, By Developers의 약자로, 개발자들을 위해 개발자들이 직접 만들어 가고 있는 네이버 개발자 지원 프로그램입니다. 네이버가 축적한 기술과 지식을 공유하고, 외
www.acmicpc.net
import sys input = sys.stdin.readline import heapq n=int(input()) arr=list(map(int, input().split())) y=min(arr) heapq.heapify(arr) tower=1 num=0 while arr: x=heapq.heappop(arr) if x==y: num+=1 else: y=x if num>tower: tower=num num=1 if num>tower: tower=num print(tower)
힙큐 자주쓰니 좋다...힝
우선 세팅다해주고 작은순으로 큐에서 빠져나옴. 그 값을 x에 저장. 근데 이게 미리 저장된 y랑 같다== 같은숫자 또나왓다? num으로 개수표현해줌. 만약 탑 수가 num보다 적으면 새로운 탑 쌓아야할거아냐?
왜냐면... 지보다 작거나 같은애를 깔고앉을수없어...! 이렇게 다돌고 출력
***ㄱㄴ데 맨 마지막 숫자를 탑에 적용 못시켯을수잇어 조심해 if문으로 굳이 자 ㄹ서줘라!
'PYTHON' 카테고리의 다른 글
비중복순열 (0) 2024.07.08 자료구조 : 데이터에 효율적으로 접근하기 위한 관리 (0) 2024.07.06 탐색 : 주어진 조건을 만족하여 데이터를 찾아내기 (0) 2024.07.05 3. 이진탐색 (0) 2023.08.07 1. 완전탐색 (0) 2023.07.18