๐Ÿ Algorithm/๋ฐฑ์ค€

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 1715๋ฒˆ: ์นด๋“œ ์ •๋ ฌํ•˜๊ธฐ(์ž๋ฐ”)

โžฐ๋ฌธ์ œ ์ •๋ ฌ๋œ ๋‘ ๋ฌถ์Œ์˜ ์ˆซ์ž ์นด๋“œ๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•˜์ž. ๊ฐ ๋ฌถ์Œ์˜ ์นด๋“œ์˜ ์ˆ˜๋ฅผ A, B๋ผ ํ•˜๋ฉด ๋ณดํ†ต ๋‘ ๋ฌถ์Œ์„ ํ•ฉ์ณ์„œ ํ•˜๋‚˜๋กœ ๋งŒ๋“œ๋Š” ๋ฐ์—๋Š” A+B ๋ฒˆ์˜ ๋น„๊ต๋ฅผ ํ•ด์•ผ ํ•œ๋‹ค. ์ด๋ฅผํ…Œ๋ฉด, 20์žฅ์˜ ์ˆซ์ž ์นด๋“œ ๋ฌถ์Œ๊ณผ 30์žฅ์˜ ์ˆซ์ž ์นด๋“œ ๋ฌถ์Œ์„ ํ•ฉ์น˜๋ ค๋ฉด 50๋ฒˆ์˜ ๋น„๊ต๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ๋งค์šฐ ๋งŽ์€ ์ˆซ์ž ์นด๋“œ ๋ฌถ์Œ์ด ์ฑ…์ƒ ์œ„์— ๋†“์—ฌ ์žˆ๋‹ค. ์ด๋“ค์„ ๋‘ ๋ฌถ์Œ์”ฉ ๊ณจ๋ผ ์„œ๋กœ ํ•ฉ์ณ๋‚˜๊ฐ„๋‹ค๋ฉด, ๊ณ ๋ฅด๋Š” ์ˆœ์„œ์— ๋”ฐ๋ผ์„œ ๋น„๊ต ํšŸ์ˆ˜๊ฐ€ ๋งค์šฐ ๋‹ฌ๋ผ์ง„๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 10์žฅ, 20์žฅ, 40์žฅ์˜ ๋ฌถ์Œ์ด ์žˆ๋‹ค๋ฉด 10์žฅ๊ณผ 20์žฅ์„ ํ•ฉ์นœ ๋’ค, ํ•ฉ์นœ 30์žฅ ๋ฌถ์Œ๊ณผ 40์žฅ์„ ํ•ฉ์นœ๋‹ค๋ฉด (10 + 20) + (30 + 40) = 100๋ฒˆ์˜ ๋น„๊ต๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ 10์žฅ๊ณผ 40์žฅ์„ ํ•ฉ์นœ ๋’ค, ํ•ฉ์นœ 50์žฅ ๋ฌถ์Œ๊ณผ 20์žฅ์„ ํ•ฉ์นœ๋‹ค๋ฉด (10 + 40) + (50 + 20..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 11866๋ฒˆ: ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ 0(Python)

๋ฌธ์ œ 11866๋ฒˆ: ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ 0 ์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ K ≤ N ≤ 1,000) www.acmicpc.net ์ œ์ถœ ์ฝ”๋“œ from collections import deque N, K = map(int, input().split()) q = deque() for i in range(1, N+1): q.append(i) li = [] while q: for i in range(K-1): q.append(q.popleft()) li.append(q.popleft()) print("") ์ด ๋ฌธ์ œ๋Š” deque๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋˜๋Š” ๋ฌธ์ œ์ด๋‹ค. popleft()๋Š” ๊ฐ€์žฅ ์™ผ์ชฝ์˜ ์›์†Œ๋ฅผ ์ œ๊ฑฐํ•ด์ฃผ๋ฉฐ ์ œ๊ฑฐํ•œ ๊ฐ’์„ return ํ•ด์ค€๋‹ค. ๋”ฐ๋ผ์„œ ์œ„์— q.append(q.popl..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 2851๋ฒˆ: ์Šˆํผ๋งˆ๋ฆฌ์˜ค(Python)

๋ฌธ์ œ 2851๋ฒˆ: ์Šˆํผ ๋งˆ๋ฆฌ์˜ค ์ฒซ์งธ ์ค„์— ๋งˆ๋ฆฌ์˜ค๊ฐ€ ๋ฐ›๋Š” ์ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋งŒ์•ฝ 100์— ๊ฐ€๊นŒ์šด ์ˆ˜๊ฐ€ 2๊ฐœ๋ผ๋ฉด (์˜ˆ: 98, 102) ๋งˆ๋ฆฌ์˜ค๋Š” ํฐ ๊ฐ’์„ ์„ ํƒํ•œ๋‹ค. www.acmicpc.net ์ œ์ถœ ์ฝ”๋“œ score = [] sum = 0 sum_under = 0 for i in range(10): score.append(int(input())) for i in range(len(score)): sum += score[i] if sum > 100: sum_under = sum - score[i] break; if abs(100-sum) == abs(100-sum_under): print(sum) else: if abs(100-sum) < abs(100-sum_under): print(sum) else : pr..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 1021๋ฒˆ: ํšŒ์ „ํ•˜๋Š” ํ(Python)

๋ฌธ์ œ 1021๋ฒˆ: ํšŒ์ „ํ•˜๋Š” ํ ์ฒซ์งธ ์ค„์— ํ์˜ ํฌ๊ธฐ N๊ณผ ๋ฝ‘์•„๋‚ด๋ ค๊ณ  ํ•˜๋Š” ์ˆ˜์˜ ๊ฐœ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , M์€ N๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ง€๋ฏผ์ด๊ฐ€ ๋ฝ‘์•„๋‚ด๋ ค๊ณ  ํ•˜๋Š” ์ˆ˜์˜ ์œ„์น˜๊ฐ€ www.acmicpc.net ์ œ์ถœ์ฝ”๋“œ N, M = map(int, input().split()) P = list(map(int, input().split())) q = [i for i in range(1, N+1)] cnt = 0 for i in range(M): # ์œ„์น˜ 0๊ณผ์˜ ๊ฑฐ๋ฆฌ ์ฐจ์ด๋กœ ์™ผ์ชฝ์œผ๋กœ or ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™ํ•  ์ง€๋ฅผ ๊ฒฐ์ • if q.index(P[i]) < len(q)-q.index(P[i]): while True: if q[0] == P[i]: del q[0] brea..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 2460๋ฒˆ: ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ 2(Python)

๋ฌธ์ œ 2460๋ฒˆ: ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ 2 ์ตœ๊ทผ์— ๊ฐœ๋ฐœ๋œ ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ๊ฐ€ 1๋ฒˆ์—ญ(์ถœ๋ฐœ์—ญ)๋ถ€ํ„ฐ 10๋ฒˆ์—ญ(์ข…์ฐฉ์—ญ)๊นŒ์ง€ 10๊ฐœ์˜ ์ •์ฐจ์—ญ์ด ์žˆ๋Š” ๋…ธ์„ ์—์„œ ์šดํ–‰๋˜๊ณ  ์žˆ๋‹ค. ์ด ๊ธฐ์ฐจ์—๋Š” ํƒ€๊ฑฐ๋‚˜ ๋‚ด๋ฆฌ๋Š” ์‚ฌ๋žŒ ์ˆ˜๋ฅผ ์ž๋™์œผ๋กœ ์ธ์‹ํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์น˜๊ฐ€ ์žˆ๋‹ค. www.acmicpc.net ์ œ์ถœ ์ฝ”๋“œ num = [] left = [0] for i in range(10): num.append(list(map(int, input().split()))) for i in range(1,11): add = num[i-1][1] - num[i-1][0] left.append(left[i-1] + add) print(max(left)) ๋จผ์ €, num ๋ฆฌ์ŠคํŠธ์— 2์ฐจ์› ๋ฐฐ์—ด๋กœ ์ž…๋ ฅ๋ฐ›์•„ append ํ•จ์ˆ˜๋กœ ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€ํ•œ๋‹ค. add๋Š” ๊ฐ ์—ญ์—์„œ ํƒ„ ์‚ฌ๋žŒ๊ณผ..

๐Ÿ Algorithm/๋ฐฑ์ค€

[๋ฐฑ์ค€] 11399๋ฒˆ: ATM(Python)

๋ฌธ์ œ 11399๋ฒˆ: ATM ์ฒซ์งธ ์ค„์— ์‚ฌ๋žŒ์˜ ์ˆ˜ N(1 ≤ N ≤ 1,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ๊ฐ ์‚ฌ๋žŒ์ด ๋ˆ์„ ์ธ์ถœํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„ Pi๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Pi ≤ 1,000) www.acmicpc.net ์ œ์ถœ ์ฝ”๋“œ N = int(input()) P = list(map(int, input().split())) total = 0 P.sort() for i in range(N): for j in range(i+1): total += P[j] print(total) ์ด ๋ฌธ์ œ๋Š” ๋จผ์ € ์ž…๋ ฅ๋ฐ›์€ ๊ฐ ์‚ฌ๋žŒ๋“ค์˜ ์ธ์ถœ ์‹œ๊ฐ„์„ ์ž‘์€ ์‹œ๊ฐ„ ๋ถ€ํ„ฐ ์ •๋ ฌ์„ ํ•ด์•ผํ•œ๋‹ค. ๋ฆฌ์ŠคํŠธ์˜ ์ •๋ ฌ์„ ์œ„ํ•ด ๋ฆฌ์ŠคํŠธ์˜ ๋‚ด๋ถ€ ์š”์†Œ๋ฅผ ์ •๋ ฌํ•ด์ฃผ๋Š” sort() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค. sort ํ•จ์ˆ˜๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— P.s..

Dhey
'๐Ÿ Algorithm/๋ฐฑ์ค€' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก