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

4๏ธโƒฃ Python56

[Python Algorithm] ๋ฌธ์„œ ๊ฒ€์ƒ‰ BOJ #1543 ๋ฌธ์ œ https://www.acmicpc.net/problem/1543 1543๋ฒˆ: ๋ฌธ์„œ ๊ฒ€์ƒ‰ ์„ธ์ค€์ด๋Š” ์˜์–ด๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ์–ด๋–ค ๋ฌธ์„œ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค๋ ค๊ณ  ํ•œ๋‹ค. ์ด ํ•จ์ˆ˜๋Š” ์–ด๋–ค ๋‹จ์–ด๊ฐ€ ์ด ๋ช‡ ๋ฒˆ ๋“ฑ์žฅํ•˜๋Š”์ง€ ์„ธ๋ ค๊ณ  ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, ์„ธ์ค€์ด์˜ ํ•จ์ˆ˜๋Š” ์ค‘๋ณต๋˜์–ด ์„ธ๋Š” ๊ฒƒ์€ ๋นผ๊ณ  ์„ธ์•ผ ํ•œ www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด doc = input() text = input() result = 0 idx = 0 while idx 2022. 2. 3.
[Python Algorithm] ๋ฒ ์ŠคํŠธ์…€๋Ÿฌ BOJ #1302 ๋ฌธ์ œ https://www.acmicpc.net/problem/1302 1302๋ฒˆ: ๋ฒ ์ŠคํŠธ์…€๋Ÿฌ ์ฒซ์งธ ์ค„์— ์˜ค๋Š˜ ํ•˜๋ฃจ ๋™์•ˆ ํŒ”๋ฆฐ ์ฑ…์˜ ๊ฐœ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ์ด ๊ฐ’์€ 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ์ฑ…์˜ ์ œ๋ชฉ์ด ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜จ๋‹ค. ์ฑ…์˜ ์ œ๋ชฉ์˜ ๊ธธ์ด๋Š” 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๊ณ  www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด import sys n = int(sys.stdin.readline()) books = [] count = [] result = [] for _ in range(n): now = sys.stdin.readline().strip() if now in books: count[books.index(now)][1] += 1 else: books.append(now) count... 2022. 2. 3.
[Python Algorithm] ๋‹จ์–ด ์ •๋ ฌ BOJ #1181 ๋ฌธ์ œ https://www.acmicpc.net/problem/1181 1181๋ฒˆ: ๋‹จ์–ด ์ •๋ ฌ ์ฒซ์งธ ์ค„์— ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 20,000) ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋‹จ์–ด๊ฐ€ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 50์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด import sys n = int(sys.stdin.readline()) result = [] for _ in range(n): now = sys.stdin.readline().strip() result.append((len(now), now)) result = list(set(result)) result.sort() for i in range(len(result)).. 2022. 2. 2.
[Python Algorithm] 2×n ํƒ€์ผ๋ง 2 BOJ #11727 ๋ฌธ์ œ https://www.acmicpc.net/problem/11727 11727๋ฒˆ: 2×n ํƒ€์ผ๋ง 2 2×n ์ง์‚ฌ๊ฐํ˜•์„ 1×2, 2×1๊ณผ 2×2 ํƒ€์ผ๋กœ ์ฑ„์šฐ๋Š” ๋ฐฉ๋ฒ•์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์•„๋ž˜ ๊ทธ๋ฆผ์€ 2×17 ์ง์‚ฌ๊ฐํ˜•์„ ์ฑ„์šด ํ•œ๊ฐ€์ง€ ์˜ˆ์ด๋‹ค. www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด n = int(input()) if n == 1: print(1) elif n == 2: print(3) else: memory = [1, 3] for i in range(2, n): memory.append((memory[i-2]*2 + memory[i-1]) % 10007) print(memory[-1]) ๐Ÿ‘‰ DP ๋ฌธ์ œ๋กœ, ์ ํ™”์‹ / ๋ฉ”๋ชจ์ด์ œ์ด์…˜ ์‚ฌ์šฉํ•ด์ฃผ๋ฉด ๋œ๋‹ค. p[n] = p[n-1] + p[n-2].. 2022. 2. 2.
[Python Algorithm] ์ด์นœ์ˆ˜ BOJ #2193 ๋ฌธ์ œ https://www.acmicpc.net/problem/2193 2193๋ฒˆ: ์ด์นœ์ˆ˜ 0๊ณผ 1๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ์ˆ˜๋ฅผ ์ด์ง„์ˆ˜๋ผ ํ•œ๋‹ค. ์ด๋Ÿฌํ•œ ์ด์ง„์ˆ˜ ์ค‘ ํŠน๋ณ„ํ•œ ์„ฑ์งˆ์„ ๊ฐ–๋Š” ๊ฒƒ๋“ค์ด ์žˆ๋Š”๋ฐ, ์ด๋“ค์„ ์ด์นœ์ˆ˜(pinary number)๋ผ ํ•œ๋‹ค. ์ด์นœ์ˆ˜๋Š” ๋‹ค์Œ์˜ ์„ฑ์งˆ์„ ๋งŒ์กฑํ•œ๋‹ค. ์ด์นœ์ˆ˜๋Š” 0์œผ๋กœ ์‹œ์ž‘ํ•˜์ง€ ์•Š www.acmicpc.net ๋‚ด ๋ฌธ์ œ ํ’€์ด n = int(input()) if n == 1: print(1) elif n == 2: print(1) else: result = [1, 1] # n์ด 0์ผ ๋•Œ, 1์ผ ๋•Œ๋ฅผ ๋ฏธ๋ฆฌ ์ €์žฅ for i in range(2, n): result.append(result[i-2] + result[i-1]) print(result[-1]) ๐Ÿ‘‰ DP ๋ฌธ์ œ๋กœ, ์ ํ™”์‹ ์‚ฌ์šฉํ•ด์ฃผ๋ฉด ๋จ.. 2022. 2. 1.