반응형 전체 글573 [유니온-파인드] 백준 20040번: 사이클 게임 / 골드 4 https://www.acmicpc.net/problem/20040 20040번: 사이클 게임 사이클 게임은 두 명의 플레이어가 차례대로 돌아가며 진행하는 게임으로, 선 플레이어가 홀수 번째 차례를, 후 플레이어가 짝수 번째 차례를 진행한다. 게임 시작 시 0 부터 n − 1 까지 고유한 www.acmicpc.net import sys input = sys.stdin.readline n, m = map(int, input().split()) parents = [i for i in range(n)] def find(parent, x): if parent[x] == x: return x else: return find(parent, parent[x]) def union(parent, a, b): a = fi.. 2021. 8. 19. [최소신장트리] 백준 4386번: 별자리 만들기 / 골드 4 https://www.acmicpc.net/problem/4386 4386번: 별자리 만들기 도현이는 우주의 신이다. 이제 도현이는 아무렇게나 널브러져 있는 n개의 별들을 이어서 별자리를 하나 만들 것이다. 별자리의 조건은 다음과 같다. 별자리를 이루는 선은 서로 다른 두 별을 일 www.acmicpc.net import sys import math input = sys.stdin.readline n = int(input()) starts = [] for i in range(n): a, b = map(float, input().split()) starts.append([a, b]) parents = [i for i in range(n)] graph = [] for i in range(n-1): for j.. 2021. 8. 19. [다이나믹 프로그래밍] 백준 17404번: RGB거리 2 / 골드 4** https://www.acmicpc.net/problem/17404 17404번: RGB거리 2 첫째 줄에 집의 수 N(2 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 각 집을 빨강, 초록, 파랑으로 칠하는 비용이 1번 집부터 한 줄에 하나씩 주어진다. 집을 칠하는 비용은 1,000보다 작거나 www.acmicpc.net import sys input = sys.stdin.readline n = int(input()) dp = [[0, 0, 0] for _ in range(n)] colors = [[0, 0, 0] for _ in range(n)] for i in range(n): colors[i] = list(map(int, input().split())) dp[0] = colors[.. 2021. 8. 19. [이진 탐색] 백준 2473번: 세 용액 / 골드 4 https://www.acmicpc.net/problem/2473 2473번: 세 용액 첫째 줄에는 전체 용액의 수 N이 입력된다. N은 3 이상 5,000 이하의 정수이다. 둘째 줄에는 용액의 특성값을 나타내는 N개의 정수가 빈칸을 사이에 두고 주어진다. 이 수들은 모두 -1,000,000,000 이상 www.acmicpc.net import sys input = sys.stdin.readline n = int(input()) lst = list(map(int, input().split())) lst.sort() if lst[-1]0: # all elem is positive print(lst[0], lst[1], lst[2]) quit() def bsearch(target, i): left = i +.. 2021. 8. 18. [이진탐색] 백준 1806번: 부분합 / 골드 4 https://www.acmicpc.net/problem/1806 1806번: 부분합 첫째 줄에 N (10 ≤ N = s: print(1) quit() for i in range(1, n): if lst[i] >= s: print(1) quit() lst[i] += lst[i-1] m.. 2021. 8. 18. [이진 탐색] 백준 1644번: 소수의 연속합 / 골드 3 https://www.acmicpc.net/problem/1644 1644번: 소수의 연속합 첫째 줄에 자연수 N이 주어진다. (1 ≤ N ≤ 4,000,000) www.acmicpc.net n = int(input()) a = [False, False] + [True]*(n-1) primes = [] for i in range(2, n+1): if a[i]: primes.append(i) for j in range(2*i, n+1, i): a[j] = False for i in range(1, len(primes)): primes[i] += primes[i-1] def bsearch(left, target): right = len(primes)-1 while left target: right = mid.. 2021. 8. 16. 이전 1 ··· 50 51 52 53 54 55 56 ··· 96 다음 반응형