[Python] ๋ณ‘ํ•ฉ์ •๋ ฌ
ยท
Algorithm/Python
๋ณ‘ํ•ฉ์ •๋ ฌ ๋ฐ์ดํ„ฐ์˜ ์š”์†Œ๋“ค์„ ๋‘ ๊ทธ๋ฃน์œผ๋กœ ๋‚˜๋ˆˆ ํ›„ ์ •๋ ฌํ•˜๊ณ , ์ •๋ ฌ๋œ ๋‘ ๊ทธ๋ฃน์„ ๋น„๊ตํ•˜๋ฉฐ ํ•˜๋‚˜๋กœ ํ•ฉ์น˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋‹ค. ๋ณ‘ํ•ฉ์ •๋ ฌ๊ณผ์ • #์ˆซ์ž 8๊ฐœ๋ฅผ ๋ฐ˜์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค group1 = [2, 8, 4, 7] group2 = [6, 1, 3, 5] #๋‘ ๊ทธ๋ฃน์„ ์ •๋ ฌํ•œ๋‹ค. group1 = [2, 4, 7, 8] group2 = [1, 3, 5, 6] #๋‘ ๊ทธ๋ฃน์„ ํ•˜๋‚˜์˜ ๊ทธ๋ฃน์œผ๋กœ ํ•ฉ์นœ๋‹ค. ๋‘ ๊ทธ๋ฃน์˜ ์ฒซ๋ฒˆ์งธ ๊ฐ’์„ ๋น„๊ตํ•ด ์ž‘์€ ๊ฐ’์„ ์ƒˆ๋กœ์šด ๋ฆฌ์ŠคํŠธ(result)์— ๋„ฃ๋Š”๋‹ค. group1 = [2, 4, 7, 8] group2 = [3, 5, 6] result = [1] #๋‘ ๊ทธ๋ฃน์˜ ์ฒซ๋ฒˆ์งธ ๊ฐ’์„ ๋น„๊ตํ•ด ์ž‘์€ ๊ฐ’์„ ์ƒˆ๋กœ์šด ๋ฆฌ์ŠคํŠธ์— ๋„ฃ๋Š” ๊ฒƒ์„ ๋ฐ˜๋ณตํ•œ๋‹ค. group1 = [4, 7, 8] group2 = [3, 5, 6] result ..
[Python] ๋ฐฑ์ค€ 2420 - ์‚ฌํŒŒ๋ฆฌ์›”๋“œ
ยท
Algorithm
๋ฌธ์ œ ์‚ฌํŒŒ๋ฆฌ์›”๋“œ๋Š” ์ธํ„ฐ๋„ท์œผ๋กœ๋งŒ ์กด์žฌํ•˜๋Š” ๋ฏธ์Šคํ…Œ๋ฆฌํ•œ ๋‚˜๋ผ์ด๋‹ค. ์‚ฌํŒŒ๋ฆฌ์›”๋“œ์—๋Š” 2๊ฐœ์˜ ์„œ๋ธŒ๋„๋ฉ”์ธ์ด seunghwan.royal.gov.sw์™€ kyuhyun.royal.gov.sw ์ด ์žˆ๋Š”๋ฐ, ์ด๊ฒƒ์ด couple.royal.gov.sw์œผ๋กœ ํ•ฉ์ณ์งˆ ๊ฒƒ์ด๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋„๋ฉ”์ธ ๊ด€๋ฆฌ ์„ผํ„ฐ SWNIC(์„ผํ„ฐ์žฅ: ๊น€๋™๊ทœ)์—๋Š” ์—„๊ฒฉํ•œ ๋ฃฐ์ด ์žˆ๋‹ค. ๋‘ ์„œ๋ธŒ๋„๋ฉ”์ธ์„ ํ•ฉ์น  ๋•Œ, ์œ ๋ช…๋„์˜ ์ฐจ์ด๊ฐ€ ๋„ˆ๋ฌด ์ฐจ์ด๋‚˜์ง€ ์•Š์„ ๊ฒฝ์šฐ์—๋งŒ ๋‘ ์„œ๋ธŒ๋„๋ฉ”์ธ์„ ๊ฒฐํ˜ผ์‹œํ‚ค๋Š” ๊ฒƒ์ด๋‹ค. ์„œ๋ธŒ๋„๋ฉ”์ธ์˜ ์œ ๋ช…๋„๋Š” ์ •์ˆ˜์ด๋‹ค. ๋‘ ์„œ๋ธŒ๋„๋ฉ”์ธ์˜ ์œ ๋ช…๋„๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ทธ ์ฐจ์ด๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— ๋‘ ๋„๋ฉ”์ธ์˜ ์œ ๋ช…๋„ N๊ณผ M์ด ์ฃผ์–ด์ง„๋‹ค. (-2,000,000,000 ≤ N, M ≤ 2,000,000,000) ์ถœ๋ ฅ ์ฒซ์งธ ์ค„์— ๋‘ ์œ ๋ช…๋„์˜ ์ฐจ์ด (..
[Python] ๋ฐฑ์ค€ 5063 - TGN
ยท
Algorithm
๋ฌธ์ œ ์ƒ๊ทผ์ด๋Š” TGN์‚ฌ์˜ ์‚ฌ์žฅ์ด๋‹ค. TGN์€ Teenager Game Network์˜ ์•ฝ์ž ๊ฐ™์ง€๋งŒ, ์‚ฌ์‹ค Temporary Group Name์˜ ์•ฝ์ž์ด๋‹ค. ์ด ํšŒ์‚ฌ๋Š” ์ฒญ์†Œ๋…„์„ ์œ„ํ•œ ์•ฑ์„ ๋งŒ๋“œ๋Š” ํšŒ์‚ฌ์ด๋‹ค. ์ผ๋…„์— ๊ฑธ์นœ ๊ฐœ๋ฐœ๊ธฐ๊ฐ„ ๋์— ๋“œ๋””์–ด ์•ฑ์„ ์™„์„ฑํ–ˆ๊ณ , ์ด์ œ ํŒ”๊ธฐ๋งŒ ํ•˜๋ฉด ๋œ๋‹ค. ์ƒ๊ทผ์ด๋Š” ๋ฐ์ดํŠธ๋ฅผ ์ธ๊ฐ„์˜ ๋‘๋‡Œ๋กœ ์ดํ•ดํ•  ์ˆ˜ ์—†์„ ์ •๋„๋กœ ๋งŽ์ด ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์—„์ฒญ๋‚œ ๋ฐ์ดํŠธ ๋น„์šฉ์ด ํ•„์š”ํ•˜๋‹ค. ์ƒ๊ทผ์ด๋Š” ๊ด‘๊ณ ๋ฅผ ์ ์ ˆํžˆ ํ•ด์„œ ์ˆ˜์ต์„ ์ตœ๋Œ€ํ•œ ์˜ฌ๋ฆฌ๋ ค๊ณ  ํ•œ๋‹ค. ์–ด๋Š ๋‚  ํ•˜๋Š˜์„ ๋ฐ”๋ผ๋ณด๋˜ ์ƒ๊ทผ์ด๋Š” ์‹œ๋ฆฌ์šฐ์Šค์˜ ๊ธฐ์šด์„ ๋ฐ›๊ฒŒ ๋˜์—ˆ๊ณ , ๊ด‘๊ณ  ํšจ๊ณผ๋ฅผ ์˜ˆ์ธกํ•˜๋Š” ๋Šฅ๋ ฅ์„ ๊ฐ–๊ฒŒ ๋˜์—ˆ๋‹ค. ๊ด‘๊ณ  ํšจ๊ณผ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ด‘๊ณ ๋ฅผ ํ•ด์•ผํ• ์ง€ ๋ง์•„์•ผํ• ์ง€ ๊ฒฐ์ •ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š”..
[Python] ๋ฐฑ์ค€ 2506 - ์ ์ˆ˜๊ณ„์‚ฐ
ยท
Algorithm
๋ฌธ์ œ OX ๋ฌธ์ œ๋Š” ๋งž๊ฑฐ๋‚˜ ํ‹€๋ฆฐ ๋‘ ๊ฒฝ์šฐ์˜ ๋‹ต์„ ๊ฐ€์ง€๋Š” ๋ฌธ์ œ๋ฅผ ๋งํ•œ๋‹ค. ์—ฌ๋Ÿฌ ๊ฐœ์˜ OX ๋ฌธ์ œ๋กœ ๋งŒ๋“ค์–ด์ง„ ์‹œํ—˜์—์„œ ์—ฐ์†์ ์œผ๋กœ ๋‹ต์„ ๋งžํžˆ๋Š” ๊ฒฝ์šฐ์—๋Š” ๊ฐ€์‚ฐ์ ์„ ์ฃผ๊ธฐ ์œ„ํ•ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ ์ˆ˜ ๊ณ„์‚ฐ์„ ํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค. 1๋ฒˆ ๋ฌธ์ œ๊ฐ€ ๋งž๋Š” ๊ฒฝ์šฐ์—๋Š” 1์ ์œผ๋กœ ๊ณ„์‚ฐํ•œ๋‹ค. ์•ž์˜ ๋ฌธ์ œ์— ๋Œ€ํ•ด์„œ๋Š” ๋‹ต์„ ํ‹€๋ฆฌ๋‹ค๊ฐ€ ๋‹ต์ด ๋งž๋Š” ์ฒ˜์Œ ๋ฌธ์ œ๋Š” 1์ ์œผ๋กœ ๊ณ„์‚ฐํ•œ๋‹ค. ๋˜ํ•œ, ์—ฐ์†์œผ๋กœ ๋ฌธ์ œ์˜ ๋‹ต์ด ๋งž๋Š” ๊ฒฝ์šฐ์—์„œ ๋‘ ๋ฒˆ์งธ ๋ฌธ์ œ๋Š” 2์ , ์„ธ ๋ฒˆ์งธ ๋ฌธ์ œ๋Š” 3์ ,..., K๋ฒˆ์งธ ๋ฌธ์ œ๋Š” K์ ์œผ๋กœ ๊ณ„์‚ฐํ•œ๋‹ค. ํ‹€๋ฆฐ ๋ฌธ์ œ๋Š” 0์ ์œผ๋กœ ๊ณ„์‚ฐํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•„๋ž˜์™€ ๊ฐ™์ด 10 ๊ฐœ์˜ OX ๋ฌธ์ œ์—์„œ ๋‹ต์ด ๋งž์€ ๋ฌธ์ œ์˜ ๊ฒฝ์šฐ์—๋Š” 1๋กœ ํ‘œ์‹œํ•˜๊ณ , ํ‹€๋ฆฐ ๊ฒฝ์šฐ์—๋Š” 0์œผ๋กœ ํ‘œ์‹œํ•˜์˜€์„ ๋•Œ, ์ ์ˆ˜ ๊ณ„์‚ฐ์€ ์•„๋ž˜ ํ‘œ์™€ ๊ฐ™์ด ๊ณ„์‚ฐ๋˜์–ด, ์ด ์ ์ˆ˜๋Š” 1+1+2+3+1+2=10 ์ ์ด๋‹ค. ์‹œ..