본문 바로가기

PS/백준46

백준 1927번: 최소힙 python 파이썬 1. 문제 https://www.acmicpc.net/problem/1927 1927번: 최소 힙 첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 0 www.acmicpc.net 2. 풀이 우선순위큐 3. 구현 import sys # sys.stdin = open('input.txt') import heapq lis = [] n = int(sys.stdin.readline().strip()) while n: n-=1 tmp = int(sys.stdin.readline().strip()) if tmp==0: if len(lis)==0: sys... 2021. 8. 6.
[테스트케이스 추가] 백준 16398 번: 행성연결, python 파이썬 1. 문제 https://www.acmicpc.net/problem/16398 16398번: 행성 연결 홍익 제국의 중심은 행성 T이다. 제국의 황제 윤석이는 행성 T에서 제국을 효과적으로 통치하기 위해서, N개의 행성 간에 플로우를 설치하려고 한다. 두 행성 간에 플로우를 설치하면 제국의 함 www.acmicpc.net 2. 풀이 3. 구현 # 최소한의 비용으로 모든 행성을 잇는 간선을 만든다 import sys # sys.stdin=open('input.txt') import heapq sys.setrecursionlimit(10**8) n = int(sys.stdin.readline().strip()) gph=[] for i in range(n): gph.append(list(map(int, sys.. 2021. 8. 6.
[테스트케이스 정리] 백준 11723 번: 집합 python, 파이썬 1.문제 https://www.acmicpc.net/problem/11723 11723번: 집합 첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다. www.acmicpc.net 2. 풀이 비트마스크 3. 구현 import sys # sys.stdin=open('input.txt') M = int(sys.stdin.readline()) bit=0 while M: M-=1 cmd = sys.stdin.readline().split() if len(cmd)==1: c = cmd[0] else: c = cmd[0] n = int(cmd[1])-1 if c=='add': bit = bit|(1 2021. 7. 23.
[테스트케이스 모음] 백준 2805번 : 나무자르기 python, 파이썬 1. 문제 https://www.acmicpc.net/problem/2805 2805번: 나무 자르기 첫째 줄에 나무의 수 N과 상근이가 집으로 가져가려고 하는 나무의 길이 M이 주어진다. (1 ≤ N ≤ 1,000,000, 1 ≤ M ≤ 2,000,000,000) 둘째 줄에는 나무의 높이가 주어진다. 나무의 높이의 합은 항상 M보 www.acmicpc.net 2. 풀이 binary search 3. 구현 import sys #sys.stdin = open('input.txt') n,m =map(int,sys.stdin.readline().split()) lis = list(map(int, sys.stdin.readline().split())) le=1 ri=max(lis) while lemid else.. 2021. 7. 20.
반응형