๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ 479

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver1] 1991๋ฒˆ_ํŠธ๋ฆฌ ์ˆœํšŒ

๋ฌธ์ œ https://www.acmicpc.net/problem/1991 1991๋ฒˆ: ํŠธ๋ฆฌ ์ˆœํšŒ ์ฒซ์งธ ์ค„์—๋Š” ์ด์ง„ ํŠธ๋ฆฌ์˜ ๋…ธ๋“œ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 26)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ ๊ฐ ๋…ธ๋“œ์™€ ๊ทธ์˜ ์™ผ์ชฝ ์ž์‹ ๋…ธ๋“œ, ์˜ค๋ฅธ์ชฝ ์ž์‹ ๋…ธ๋“œ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋…ธ๋“œ์˜ ์ด๋ฆ„์€ A๋ถ€ํ„ฐ ์ฐจ๋ก€๋Œ€๋กœ ์•ŒํŒŒ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1991๋ฒˆ - ํŠธ๋ฆฌ ์ˆœํšŒ n = int(input()) tree = {} for _ in range(n): root, left, right = input().split() tree[root] = [left, right] def preorder(root): if root != '.': print(root, end='') preorder(tree[root][0]) # l..

๐ŸŸจ [Java] ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ / ๋ชจ๋“ˆ

์ž๋ฐ” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ž€ ? ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ํ”„๋กœ๊ทธ๋žจ ๊ฐœ๋ฐœ ์‹œ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํด๋ž˜์Šค์™€ ์ธํ„ฐํŽ˜์ด์Šค๋“ค์„ ๋ชจ์•„๋†“์€ ๊ฒƒ์„ ๋งํ•œ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ JAR ์••์ถ• ํŒŒ์ผ ํ˜•ํƒœ๋กœ ์กด์žฌํ•œ๋‹ค. JAR ํŒŒ์ผ์—๋Š” ํด๋ž˜์Šค์™€ ์ธํ„ฐํŽ˜์ด์Šค์˜ ๋ฐ”์ดํŠธ์ฝ”๋“œ ํŒŒ์ผ์ด ์••์ถ•๋˜์–ด ์žˆ๋‹ค. ํŠน์ • ํด๋ž˜์Šค์™€ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์—ฌ๋Ÿฌ ์‘์šฉํ”„๋กœ๊ทธ๋žจ์„ ๊ฐœ๋ฐœํ•  ๋•Œ ๊ณตํ†ต์œผ๋กœ ์ž์ฃผ ์‚ฌ์šฉ๋œ๋‹ค๋ฉด JAR ํŒŒ์ผ๋กœ ์••์ถ•ํ•ด์„œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. ํ”„๋กœ๊ทธ๋žจ ๊ฐœ๋ฐœ ์‹œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•˜๋ ค๋ฉด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ JAR ํŒŒ์ผ์„ ClassPath์— ์ถ”๊ฐ€ํ•ด์•ผ ํ•œ๋‹ค. ClassPath๋ž€ ๋ง ๊ทธ๋Œ€๋กœ ํด๋ž˜์Šค๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•œ ๊ฒฝ๋กœ์ด๋‹ค. my_lib ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ Eclipse ๊ธฐ์ค€์œผ๋กœ [File] - [New] - [Java Project] ๋ฅผ ์„ ํƒํ•œ๋‹ค. Project name ์€ my_lib์œผ๋กœ ์ ..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Silver3] 15654๋ฒˆ_N๊ณผM(5)

๋ฌธ์ œ https://www.acmicpc.net/problem/15654 15654๋ฒˆ: N๊ณผ M (5) N๊ฐœ์˜ ์ž์—ฐ์ˆ˜์™€ ์ž์—ฐ์ˆ˜ M์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์•„๋ž˜ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ๊ธธ์ด๊ฐ€ M์ธ ์ˆ˜์—ด์„ ๋ชจ๋‘ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. N๊ฐœ์˜ ์ž์—ฐ์ˆ˜๋Š” ๋ชจ๋‘ ๋‹ค๋ฅธ ์ˆ˜์ด๋‹ค. N๊ฐœ์˜ ์ž์—ฐ์ˆ˜ ์ค‘์—์„œ M๊ฐœ๋ฅผ ๊ณ ๋ฅธ ์ˆ˜์—ด www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 15654๋ฒˆ ๋ฌธ์ œ - N๊ณผ M(5) from itertools import permutations n, m = map(int, input().split()) new_list = list(map(int, input().split())) new_list = sorted(new_list) #์ˆœ์„œ๋Œ€๋กœ ๋‚˜์˜ค๊ฒŒ ์ •๋ ฌ ๋จผ์ € for numbers in list(permutations..

โฌ› [Programmers] [Python] [Level2] ์นด๋“œ ๋ญ‰์น˜

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/159994 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - ์นด๋“œ ๋ญ‰์น˜ from collections import deque def solution(cards1, cards2, goal): cards1 = deque(cards1) cards2 = deque(cards2) for i in range(len(goal)): if cards1 and cards1[0] == goal[i]: cards1.popleft() eli..

โฌ› [Programmers] [Python] [Level2] ๋” ๋งต๊ฒŒ

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/42626 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - ๋” ๋งต๊ฒŒ import heapq def solution(scoville, k): answer = 0 heapq.heapify(scoville) while scoville[0] < k: heapq.heappush(scoville, heapq.heappop(scoville) + heapq.heappop(scoville) * 2) answer += 1 if len(..

โฌ› [Programmers] [Python] [2018 KAKAO BLIND RECRUITMENT] [Level2] [3์ฐจ] n์ง„์ˆ˜ ๊ฒŒ์ž„

๋ฌธ์ œ https://school.programmers.co.kr/learn/courses/30/lessons/17687 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ํ’€์ด # ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - n์ง„์ˆ˜ ๊ฒŒ์ž„ def convert(n, base): arr = '0123456789ABCDEF' q, r = divmod(n, base) if q == 0: return arr[r] else: return convert(q, base) + arr[r] def solution(n, t, m, p): answer = '' candidate = [] for i in..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold3] 2206๋ฒˆ_๋ฒฝ ๋ถ€์ˆ˜๊ณ  ์ด๋™ํ•˜๊ธฐ

๋ฌธ์ œ https://www.acmicpc.net/problem/2206 2206๋ฒˆ: ๋ฒฝ ๋ถ€์ˆ˜๊ณ  ์ด๋™ํ•˜๊ธฐ N×M์˜ ํ–‰๋ ฌ๋กœ ํ‘œํ˜„๋˜๋Š” ๋งต์ด ์žˆ๋‹ค. ๋งต์—์„œ 0์€ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณณ์„ ๋‚˜ํƒ€๋‚ด๊ณ , 1์€ ์ด๋™ํ•  ์ˆ˜ ์—†๋Š” ๋ฒฝ์ด ์žˆ๋Š” ๊ณณ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๋‹น์‹ ์€ (1, 1)์—์„œ (N, M)์˜ ์œ„์น˜๊นŒ์ง€ ์ด๋™ํ•˜๋ ค ํ•˜๋Š”๋ฐ, ์ด๋•Œ ์ตœ๋‹จ ๊ฒฝ๋กœ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 2206๋ฒˆ ๋ฌธ์ œ - ๋ฒฝ ๋ถ€์ˆ˜๊ณ  ์ด๋™ํ•˜๊ธฐ from collections import deque n, m = map(int, input().split()) graph = [] for _ in range(n): graph.append(list(map(int, input()))) dx, dy = [-1, 1, 0, 0], [0, 0, -1, 1] def bfs..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 1753๋ฒˆ_์ตœ๋‹จ๊ฒฝ๋กœ

๋ฌธ์ œ https://www.acmicpc.net/problem/1753 1753๋ฒˆ: ์ตœ๋‹จ๊ฒฝ๋กœ ์ฒซ์งธ ์ค„์— ์ •์ ์˜ ๊ฐœ์ˆ˜ V์™€ ๊ฐ„์„ ์˜ ๊ฐœ์ˆ˜ E๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ V ≤ 20,000, 1 ≤ E ≤ 300,000) ๋ชจ๋“  ์ •์ ์—๋Š” 1๋ถ€ํ„ฐ V๊นŒ์ง€ ๋ฒˆํ˜ธ๊ฐ€ ๋งค๊ฒจ์ ธ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์‹œ์ž‘ ์ •์ ์˜ ๋ฒˆํ˜ธ K(1 ≤ K ≤ V)๊ฐ€ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 1753๋ฒˆ ๋ฌธ์ œ - ์ตœ๋‹จ๊ฒฝ๋กœ import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) import heapq n, m = map(int, input().split()) k = int(input()) INF = int(1e9) graph = [[] * (n+1) for _ in r..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 9663๋ฒˆ_N-Queen

๋ฌธ์ œ https://www.acmicpc.net/problem/9663 9663๋ฒˆ: N-Queen N-Queen ๋ฌธ์ œ๋Š” ํฌ๊ธฐ๊ฐ€ N × N์ธ ์ฒด์ŠคํŒ ์œ„์— ํ€ธ N๊ฐœ๋ฅผ ์„œ๋กœ ๊ณต๊ฒฉํ•  ์ˆ˜ ์—†๊ฒŒ ๋†“๋Š” ๋ฌธ์ œ์ด๋‹ค. N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ํ€ธ์„ ๋†“๋Š” ๋ฐฉ๋ฒ•์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 9663๋ฒˆ ๋ฌธ์ œ - N-Queen import sys input = sys.stdin.readline n = int(input().rstrip()) answer = 0 row = [0] * n def is_promising(x): for i in range(x): if row[x] == row[i] or abs(row[x]-row[i]) == abs(x-i): return False retur..

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] 5052๋ฒˆ_์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก

๋ฌธ์ œ https://www.acmicpc.net/problem/5052 5052๋ฒˆ: ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก ์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ t๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ t ≤ 50) ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ์ฒซ์งธ ์ค„์—๋Š” ์ „ํ™”๋ฒˆํ˜ธ์˜ ์ˆ˜ n์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ n ≤ 10000) ๋‹ค์Œ n๊ฐœ์˜ ์ค„์—๋Š” ๋ชฉ๋ก์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ „ํ™”๋ฒˆํ˜ธ๊ฐ€ www.acmicpc.net ํ’€์ด # ๋ฐฑ์ค€ 5052๋ฒˆ ๋ฌธ์ œ - ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก import sys t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) phone_book = [str(sys.stdin.readline().strip()) for _ in range(n)] # ์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ›๋Š”๋‹ค. phone..