๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

4๏ธโƒฃ Python56

[Python Algorithm] ์œ ๊ธฐ๋† ๋ฐฐ์ถ” BOJ #1012 ๋ฌธ์ œ https://www.acmicpc.net/problem/1012 1012๋ฒˆ: ์œ ๊ธฐ๋† ๋ฐฐ์ถ” ์ฐจ์„ธ๋Œ€ ์˜๋†์ธ ํ•œ๋‚˜๋Š” ๊ฐ•์›๋„ ๊ณ ๋žญ์ง€์—์„œ ์œ ๊ธฐ๋† ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค. ๋†์•ฝ์„ ์“ฐ์ง€ ์•Š๊ณ  ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๋ ค๋ฉด ๋ฐฐ์ถ”๋ฅผ ํ•ด์ถฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ•œ๋‚˜๋Š” ํ•ด์ถฉ ๋ฐฉ์ง€์— www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด t = int(input()) dx = [0, 0, -1, 1] dy = [-1, 1, 0, 0] queue = [] for _ in range(t): m, n, k = map(int, input().split()) # ๊ฐ€๋กœ๊ธธ์ด, ์„ธ๋กœ๊ธธ์ด, ๋ฐฐ์ถ” ๊ฐœ์ˆ˜ space = [[0] * m for _ in range(n)] # ๋ฐฐ์ถ”๋ฐญ count = 0 for _ in range(k): y, x = .. 2022. 1. 27.
[Python Algorithm] ์ •์ˆ˜ ์‚ผ๊ฐํ˜• BOJ #1932 ๋ฌธ์ œ https://www.acmicpc.net/problem/1932 1932๋ฒˆ: ์ •์ˆ˜ ์‚ผ๊ฐํ˜• ์ฒซ์งธ ์ค„์— ์‚ผ๊ฐํ˜•์˜ ํฌ๊ธฐ n(1 ≤ n ≤ 500)์ด ์ฃผ์–ด์ง€๊ณ , ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ n+1๋ฒˆ์งธ ์ค„๊นŒ์ง€ ์ •์ˆ˜ ์‚ผ๊ฐํ˜•์ด ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด n = int(input()) memory = [int(input())] for _ in range(1, n): now = list(map(lambda x: int(x), input().split())) for i in range(len(now)): if i == 0: now[0] += memory[0] elif i == len(now)-1: now[-1] += memory[-1] else: if memory[i-1] > memory[i]: now[.. 2021. 12. 17.
[Python Algorithm] RGB๊ฑฐ๋ฆฌ BOJ #1149 ๋ฌธ์ œ https://www.acmicpc.net/problem/1149 1149๋ฒˆ: RGB๊ฑฐ๋ฆฌ ์ฒซ์งธ ์ค„์— ์ง‘์˜ ์ˆ˜ N(2 ≤ N ≤ 1,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ ์ง‘์„ ๋นจ๊ฐ•, ์ดˆ๋ก, ํŒŒ๋ž‘์œผ๋กœ ์น ํ•˜๋Š” ๋น„์šฉ์ด 1๋ฒˆ ์ง‘๋ถ€ํ„ฐ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ง‘์„ ์น ํ•˜๋Š” ๋น„์šฉ์€ 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด n = int(input()) r, g, b = map(int, input().split()) red = [r] green = [g] blue = [b] for i in range(1, n): r, g, b = map(int, input().split()) red.append(r + min(green[i-1], blue[i-1])) green.append(.. 2021. 12. 16.
[Python Algorithm] ํ‰๋ฒ”ํ•œ ๋ฐฐ๋‚ญ BOJ #12865 ๋ฌธ์ œ https://www.acmicpc.net/problem/12865 12865๋ฒˆ: ํ‰๋ฒ”ํ•œ ๋ฐฐ๋‚ญ ์ฒซ ์ค„์— ๋ฌผํ’ˆ์˜ ์ˆ˜ N(1 ≤ N ≤ 100)๊ณผ ์ค€์„œ๊ฐ€ ๋ฒ„ํ‹ธ ์ˆ˜ ์žˆ๋Š” ๋ฌด๊ฒŒ K(1 ≤ K ≤ 100,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‘ ๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๊ฑฐ์ณ ๊ฐ ๋ฌผ๊ฑด์˜ ๋ฌด๊ฒŒ W(1 ≤ W ≤ 100,000)์™€ ํ•ด๋‹น ๋ฌผ๊ฑด์˜ ๊ฐ€์น˜ V(0 ≤ V ≤ 1,000) www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด n, k = map(int, input().split()) memory = [[0]*(k+1) for _ in range(n+1)] # [n+1][k+1] ํฌ๊ธฐ์˜ 0์œผ๋กœ ์ฑ„์›Œ์ง„ ๋ฐฐ์—ด for i in range(1, n+1): w, v = map(int, input().split()) # ํ˜„์žฌ ์ž…๋ ฅ๋œ ๋ฌผ๊ฑด์˜ ๋ฌด๊ฒŒ,.. 2021. 11. 25.
[Python Algorithm] ์ˆซ์ž์˜ ํ‘œํ˜„ Programmers(Lv.2) ๋ฌธ์ œ https://programmers.co.kr/learn/courses/30/lessons/12924 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ˆซ์ž์˜ ํ‘œํ˜„ Finn์€ ์š”์ฆ˜ ์ˆ˜ํ•™๊ณต๋ถ€์— ๋น ์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ์ˆ˜ํ•™ ๊ณต๋ถ€๋ฅผ ํ•˜๋˜ Finn์€ ์ž์—ฐ์ˆ˜ n์„ ์—ฐ์†ํ•œ ์ž์—ฐ์ˆ˜๋“ค๋กœ ํ‘œํ˜„ ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์—ฌ๋Ÿฌ๊ฐœ๋ผ๋Š” ์‚ฌ์‹ค์„ ์•Œ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ๋“ค์–ด 15๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด 4๊ฐ€์ง€๋กœ ํ‘œํ˜„ ํ•  programmers.co.kr ๋‚ด ๋ฌธ์ œ ํ’€์ด def solution(n): answer = 0 for i in range(1, n+1): sum = 0 for j in range(i, n+1): sum += j if sum == n: answer += 1 break elif sum > n: break return answer # ์ž…์ถœ๋ ฅ ์˜ˆ์ œ print(solution.. 2021. 11. 22.