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

4๏ธโƒฃ Python56

[Python Algorithm] ํฌ๋„์ฃผ ์‹œ์‹ BOJ #2156 ๋ฌธ์ œ https://www.acmicpc.net/problem/2156 2156๋ฒˆ: ํฌ๋„์ฃผ ์‹œ์‹ ํšจ์ฃผ๋Š” ํฌ๋„์ฃผ ์‹œ์‹ํšŒ์— ๊ฐ”๋‹ค. ๊ทธ ๊ณณ์— ๊ฐ”๋”๋‹ˆ, ํ…Œ์ด๋ธ” ์œ„์— ๋‹ค์–‘ํ•œ ํฌ๋„์ฃผ๊ฐ€ ๋“ค์–ด์žˆ๋Š” ํฌ๋„์ฃผ ์ž”์ด ์ผ๋ ฌ๋กœ ๋†“์—ฌ ์žˆ์—ˆ๋‹ค. ํšจ์ฃผ๋Š” ํฌ๋„์ฃผ ์‹œ์‹์„ ํ•˜๋ ค๊ณ  ํ•˜๋Š”๋ฐ, ์—ฌ๊ธฐ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‘ ๊ฐ€์ง€ ๊ทœ www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด import sys n = int(sys.stdin.readline()) wine = [] for _ in range(n): wine.append(int(sys.stdin.readline())) if n == 1: print(wine[0]) elif n == 2: print(wine[0]+wine[1]) elif n == 3: print(max(wine[0]+wine[2], wi.. 2022. 1. 31.
[Python Algorithm] ์—ฐ์†ํ•ฉ BOJ #1912 ๋ฌธ์ œ https://www.acmicpc.net/problem/1912 1912๋ฒˆ: ์—ฐ์†ํ•ฉ ์ฒซ์งธ ์ค„์— ์ •์ˆ˜ n(1 ≤ n ≤ 100,000)์ด ์ฃผ์–ด์ง€๊ณ  ๋‘˜์งธ ์ค„์—๋Š” n๊ฐœ์˜ ์ •์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ ์ˆ˜์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ์ˆ˜๋Š” -1,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค. www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด import sys sys.setrecursionlimit(1000000) n = int(input()) nums = list(map(int, input().split())) sums = [nums[0]] for i in range(1, n): if nums[i] < sums[-1] + nums[i]: sums.append(sums[-1] + nums[i]) else: sums.appen.. 2022. 1. 31.
[Python Algorithm] ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ์ˆ˜์—ด BOJ #11053 ๋ฌธ์ œ https://www.acmicpc.net/problem/11053 11053๋ฒˆ: ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด ์ˆ˜์—ด A๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ˆ˜์—ด A = {10, 20, 10, 30, 20, 50} ์ธ ๊ฒฝ์šฐ์— ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์€ A = {10, 20, 10, 30, 20, 50} ์ด www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด n = int(input()) permu = list(map(int, input().split())) count = [1] # ์ฒซ ๋ฒˆ์งธ ์ˆซ์ž์˜ ๊ธธ์ด๋Š” ์–ด์ฐจํ”ผ 1์ด๋ฏ€๋กœ ๋ฏธ๋ฆฌ ์ถ”๊ฐ€ counting = 0 def find(now): global counting for i in reversed(range(l.. 2022. 1. 30.
[Python Algorithm] ์„ฌ์˜ ๊ฐœ์ˆ˜ BOJ #4963 ๋ฌธ์ œ https://www.acmicpc.net/problem/4963 4963๋ฒˆ: ์„ฌ์˜ ๊ฐœ์ˆ˜ ์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ์ฒซ์งธ ์ค„์—๋Š” ์ง€๋„์˜ ๋„ˆ๋น„ w์™€ ๋†’์ด h๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. w์™€ h๋Š” 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์–‘์˜ ์ •์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ h๊ฐœ ์ค„์—๋Š” ์ง€๋„ www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด import sys sys.setrecursionlimit(10000) while True: w, h = map(int, sys.stdin.readline().split()) if w == 0 and h == 0: break space = [list(map(int, sys.stdin.readline().split())) for _ in range(h)] dx = [0, 0.. 2022. 1. 30.
[Python Algorithm] ํ† ๋งˆํ†  BOJ #7576 ๋ฌธ์ œ https://www.acmicpc.net/problem/7576 7576๋ฒˆ: ํ† ๋งˆํ†  ์ฒซ ์ค„์—๋Š” ์ƒ์ž์˜ ํฌ๊ธฐ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋‘ ์ •์ˆ˜ M,N์ด ์ฃผ์–ด์ง„๋‹ค. M์€ ์ƒ์ž์˜ ๊ฐ€๋กœ ์นธ์˜ ์ˆ˜, N์€ ์ƒ์ž์˜ ์„ธ๋กœ ์นธ์˜ ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๋‹จ, 2 ≤ M,N ≤ 1,000 ์ด๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ๋Š” ํ•˜๋‚˜์˜ ์ƒ์ž์— ์ €์žฅ๋œ ํ† ๋งˆํ†  www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด import sys, copy m, n = map(int, sys.stdin.readline().split()) storage = [list(map(int, sys.stdin.readline().split())) for _ in range(n)] queue = [] dx = [0, 0, -1, 1] dy = [-1, 1, 0, 0] countCheck = cop.. 2022. 1. 30.