์ „์ฒด ๊ธ€ 278

[BOJ/Step8] 2839 : ์„คํƒ• ๋ฐฐ๋‹ฌ (JAVA)

www.acmicpc.net/problem/2839 2839๋ฒˆ: ์„คํƒ• ๋ฐฐ๋‹ฌ ์ƒ๊ทผ์ด๋Š” ์š”์ฆ˜ ์„คํƒ•๊ณต์žฅ์—์„œ ์„คํƒ•์„ ๋ฐฐ๋‹ฌํ•˜๊ณ  ์žˆ๋‹ค. ์ƒ๊ทผ์ด๋Š” ์ง€๊ธˆ ์‚ฌํƒ•๊ฐ€๊ฒŒ์— ์„คํƒ•์„ ์ •ํ™•ํ•˜๊ฒŒ Nํ‚ฌ๋กœ๊ทธ๋žจ์„ ๋ฐฐ๋‹ฌํ•ด์•ผ ํ•œ๋‹ค. ์„คํƒ•๊ณต์žฅ์—์„œ ๋งŒ๋“œ๋Š” ์„คํƒ•์€ ๋ด‰์ง€์— ๋‹ด๊ฒจ์ ธ ์žˆ๋‹ค. ๋ด‰์ง€๋Š” 3ํ‚ฌ๋กœ๊ทธ www.acmicpc.net ๋ฌธ์ œ ์ƒ๊ทผ์ด๋Š” ์š”์ฆ˜ ์„คํƒ•๊ณต์žฅ์—์„œ ์„คํƒ•์„ ๋ฐฐ๋‹ฌํ•˜๊ณ  ์žˆ๋‹ค. ์ƒ๊ทผ์ด๋Š” ์ง€๊ธˆ ์‚ฌํƒ•๊ฐ€๊ฒŒ์— ์„คํƒ•์„ ์ •ํ™•ํ•˜๊ฒŒ Nํ‚ฌ๋กœ๊ทธ๋žจ์„ ๋ฐฐ๋‹ฌํ•ด์•ผ ํ•œ๋‹ค. ์„คํƒ•๊ณต์žฅ์—์„œ ๋งŒ๋“œ๋Š” ์„คํƒ•์€ ๋ด‰์ง€์— ๋‹ด๊ฒจ์ ธ ์žˆ๋‹ค. ๋ด‰์ง€๋Š” 3ํ‚ฌ๋กœ๊ทธ๋žจ ๋ด‰์ง€์™€ 5ํ‚ฌ๋กœ๊ทธ๋žจ ๋ด‰์ง€๊ฐ€ ์žˆ๋‹ค. ์ƒ๊ทผ์ด๋Š” ๊ท€์ฐฎ๊ธฐ ๋•Œ๋ฌธ์—, ์ตœ๋Œ€ํ•œ ์ ์€ ๋ด‰์ง€๋ฅผ ๋“ค๊ณ  ๊ฐ€๋ ค๊ณ  ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, 18ํ‚ฌ๋กœ๊ทธ๋žจ ์„คํƒ•์„ ๋ฐฐ๋‹ฌํ•ด์•ผ ํ•  ๋•Œ, 3ํ‚ฌ๋กœ๊ทธ๋žจ ๋ด‰์ง€ 6๊ฐœ๋ฅผ ๊ฐ€์ ธ๊ฐ€๋„ ๋˜์ง€๋งŒ, 5ํ‚ฌ๋กœ๊ทธ๋žจ 3๊ฐœ์™€ 3ํ‚ฌ๋กœ๊ทธ๋žจ 1๊ฐœ๋ฅผ ๋ฐฐ๋‹ฌํ•˜๋ฉด,..

[BOJ/Step8] 2775 : ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ (JAVA)

www.acmicpc.net/problem/2775 2775๋ฒˆ: ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ ์ฒซ ๋ฒˆ์งธ ์ค„์— Test case์˜ ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ๊ฐ์˜ ์ผ€์ด์Šค๋งˆ๋‹ค ์ž…๋ ฅ์œผ๋กœ ์ฒซ ๋ฒˆ์งธ ์ค„์— ์ •์ˆ˜ k, ๋‘ ๋ฒˆ์งธ ์ค„์— ์ •์ˆ˜ n์ด ์ฃผ์–ด์ง„๋‹ค www.acmicpc.net ๋ฌธ์ œ ํ‰์†Œ ๋ฐ˜์ƒํšŒ์— ์ฐธ์„ํ•˜๋Š” ๊ฒƒ์„ ์ข‹์•„ํ•˜๋Š” ์ฃผํฌ๋Š” ์ด๋ฒˆ ๊ธฐํšŒ์— ๋ถ€๋…€ํšŒ์žฅ์ด ๋˜๊ณ  ์‹ถ์–ด ๊ฐ ์ธต์˜ ์‚ฌ๋žŒ๋“ค์„ ๋ถˆ๋Ÿฌ ๋ชจ์•„ ๋ฐ˜์ƒํšŒ๋ฅผ ์ฃผ์ตœํ•˜๋ ค๊ณ  ํ•œ๋‹ค. ์ด ์•„ํŒŒํŠธ์— ๊ฑฐ์ฃผ๋ฅผ ํ•˜๋ ค๋ฉด ์กฐ๊ฑด์ด ์žˆ๋Š”๋ฐ, “a์ธต์˜ bํ˜ธ์— ์‚ด๋ ค๋ฉด ์ž์‹ ์˜ ์•„๋ž˜(a-1)์ธต์˜ 1ํ˜ธ๋ถ€ํ„ฐ bํ˜ธ๊นŒ์ง€ ์‚ฌ๋žŒ๋“ค์˜ ์ˆ˜์˜ ํ•ฉ๋งŒํผ ์‚ฌ๋žŒ๋“ค์„ ๋ฐ๋ ค์™€ ์‚ด์•„์•ผ ํ•œ๋‹ค” ๋Š” ๊ณ„์•ฝ ์กฐํ•ญ์„ ๊ผญ ์ง€ํ‚ค๊ณ  ๋“ค์–ด์™€์•ผ ํ•œ๋‹ค. ์•„ํŒŒํŠธ์— ๋น„์–ด์žˆ๋Š” ์ง‘์€ ์—†๊ณ  ๋ชจ๋“  ๊ฑฐ์ฃผ๋ฏผ๋“ค์ด ์ด ๊ณ„์•ฝ ์กฐ๊ฑด์„ ์ง€ํ‚ค๊ณ  ์™”๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ, ์ฃผ์–ด์ง€๋Š” ์–‘์˜ ์ •์ˆ˜ k..

[BOJ/Step8] 10250 : ACM ํ˜ธํ…” (JAVA)

www.acmicpc.net/problem/10250 10250๋ฒˆ: ACM ํ˜ธํ…” ํ”„๋กœ๊ทธ๋žจ์€ ํ‘œ์ค€ ์ž…๋ ฅ์—์„œ ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›๋Š”๋‹ค. ํ”„๋กœ๊ทธ๋žจ์˜ ์ž…๋ ฅ์€ T ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋Š”๋ฐ T ๋Š” ์ž…๋ ฅ์˜ ๋งจ ์ฒซ ์ค„์— ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋Š” ํ•œ ํ–‰์œผ๋กœ์„œ H, W, N, ์„ธ ์ •์ˆ˜ www.acmicpc.net ๋ฌธ์ œ ACM ํ˜ธํ…” ๋งค๋‹ˆ์ € ์ง€์šฐ๋Š” ์†๋‹˜์ด ๋„์ฐฉํ•˜๋Š” ๋Œ€๋กœ ๋นˆ ๋ฐฉ์„ ๋ฐฐ์ •ํ•˜๊ณ  ์žˆ๋‹ค. ๊ณ ๊ฐ ์„ค๋ฌธ์กฐ์‚ฌ์— ๋”ฐ๋ฅด๋ฉด ์†๋‹˜๋“ค์€ ํ˜ธํ…” ์ •๋ฌธ์œผ๋กœ๋ถ€ํ„ฐ ๊ฑธ์–ด์„œ ๊ฐ€์žฅ ์งง์€ ๊ฑฐ๋ฆฌ์— ์žˆ๋Š” ๋ฐฉ์„ ์„ ํ˜ธํ•œ๋‹ค๊ณ  ํ•œ๋‹ค. ์—ฌ๋Ÿฌ๋ถ„์€ ์ง€์šฐ๋ฅผ ๋„์™€ ์ค„ ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๊ณ ์ž ํ•œ๋‹ค. ์ฆ‰ ์„ค๋ฌธ์กฐ์‚ฌ ๊ฒฐ๊ณผ ๋Œ€๋กœ ํ˜ธํ…” ์ •๋ฌธ์œผ๋กœ๋ถ€ํ„ฐ ๊ฑท๋Š” ๊ฑฐ๋ฆฌ๊ฐ€ ๊ฐ€์žฅ ์งง๋„๋ก ๋ฐฉ์„ ๋ฐฐ์ •ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๊ณ ์ž ํ•œ๋‹ค. ๋ฌธ์ œ๋ฅผ ๋‹จ์ˆœํ™”ํ•˜๊ธฐ ์œ„ํ•ด์„œ ํ˜ธํ…”์€ ์ง์‚ฌ๊ฐํ˜• ๋ชจ์–‘์ด๋ผ๊ณ  ๊ฐ€์ •..

[BOJ/Step8] 2869 : ๋‹ฌํŒฝ์ด๋Š” ์˜ฌ๋ผ๊ฐ€๊ณ  ์‹ถ๋‹ค (JAVA)

www.acmicpc.net/problem/2869 2869๋ฒˆ: ๋‹ฌํŒฝ์ด๋Š” ์˜ฌ๋ผ๊ฐ€๊ณ  ์‹ถ๋‹ค ์ฒซ์งธ ์ค„์— ์„ธ ์ •์ˆ˜ A, B, V๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด์„œ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ B < A ≤ V ≤ 1,000,000,000) www.acmicpc.net ๋ฌธ์ œ ๋•… ์œ„์— ๋‹ฌํŒฝ์ด๊ฐ€ ์žˆ๋‹ค. ์ด ๋‹ฌํŒฝ์ด๋Š” ๋†’์ด๊ฐ€ V๋ฏธํ„ฐ์ธ ๋‚˜๋ฌด ๋ง‰๋Œ€๋ฅผ ์˜ฌ๋ผ๊ฐˆ ๊ฒƒ์ด๋‹ค. ๋‹ฌํŒฝ์ด๋Š” ๋‚ฎ์— A๋ฏธํ„ฐ ์˜ฌ๋ผ๊ฐˆ ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ, ๋ฐค์— ์ž ์„ ์ž๋Š” ๋™์•ˆ B๋ฏธํ„ฐ ๋ฏธ๋„๋Ÿฌ์ง„๋‹ค. ๋˜, ์ •์ƒ์— ์˜ฌ๋ผ๊ฐ„ ํ›„์—๋Š” ๋ฏธ๋„๋Ÿฌ์ง€์ง€ ์•Š๋Š”๋‹ค. ๋‹ฌํŒฝ์ด๊ฐ€ ๋‚˜๋ฌด ๋ง‰๋Œ€๋ฅผ ๋ชจ๋‘ ์˜ฌ๋ผ๊ฐ€๋ ค๋ฉด, ๋ฉฐ์น ์ด ๊ฑธ๋ฆฌ๋Š”์ง€ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— ์„ธ ์ •์ˆ˜ A, B, V๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด์„œ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ B < A ≤ V ≤ 1,000,000,000) ์ถœ๋ ฅ ์ฒซ์งธ ์ค„์— ๋‹ฌํŒฝ์ด๊ฐ€ ๋‚˜๋ฌด ๋ง‰๋Œ€..

[JAVA] Math ํด๋ž˜์Šค

docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/Math.html Math (Java SE 15 & JDK 15) public final class Math extends Object The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. Unlike some of the numeric methods of class StrictMath, docs.oracle.com java.lang์— ์†ํ•ด์žˆ๋Š” ํด๋ž˜์Šค. ์ˆ˜ํ•™์—์„œ ..

[BOJ/Step8] 1193 : ๋ถ„์ˆ˜์ฐพ๊ธฐ (JAVA)

www.acmicpc.net/problem/1193 1193๋ฒˆ: ๋ถ„์ˆ˜์ฐพ๊ธฐ ์ฒซ์งธ ์ค„์— X(1 ≤ X ≤ 10,000,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ๋ฌธ์ œ ๋ฌดํ•œํžˆ ํฐ ๋ฐฐ์—ด์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ถ„์ˆ˜๋“ค์ด ์ ํ˜€์žˆ๋‹ค. 1/1 1/2 1/3 1/4 1/5 … 2/1 2/2 2/3 2/4 … … 3/1 3/2 3/3 … … … 4/1 4/2 … … … … 5/1 … … … … … … … … … … … ์ด์™€ ๊ฐ™์ด ๋‚˜์—ด๋œ ๋ถ„์ˆ˜๋“ค์„ 1/1 -> 1/2 -> 2/1 -> 3/1 -> 2/2 -> … ๊ณผ ๊ฐ™์€ ์ง€๊ทธ์žฌ๊ทธ ์ˆœ์„œ๋กœ ์ฐจ๋ก€๋Œ€๋กœ 1๋ฒˆ, 2๋ฒˆ, 3๋ฒˆ, 4๋ฒˆ, 5๋ฒˆ, … ๋ถ„์ˆ˜๋ผ๊ณ  ํ•˜์ž. X๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, X๋ฒˆ์งธ ๋ถ„์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— X(1 ≤ X ≤ 10,000,000)๊ฐ€ ์ฃผ์–ด์ง„..

[BOJ/Step8] 2292 : ๋ฒŒ์ง‘ (JAVA)

www.acmicpc.net/problem/2292 2292๋ฒˆ: ๋ฒŒ์ง‘ ์œ„์˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ์œก๊ฐํ˜•์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฒŒ์ง‘์ด ์žˆ๋‹ค. ๊ทธ๋ฆผ์—์„œ ๋ณด๋Š” ๋ฐ”์™€ ๊ฐ™์ด ์ค‘์•™์˜ ๋ฐฉ 1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ์ด์›ƒํ•˜๋Š” ๋ฐฉ์— ๋Œ์•„๊ฐ€๋ฉด์„œ 1์”ฉ ์ฆ๊ฐ€ํ•˜๋Š” ๋ฒˆํ˜ธ๋ฅผ ์ฃผ์†Œ๋กœ ๋งค๊ธธ ์ˆ˜ ์žˆ๋‹ค. ์ˆซ์ž N์ด ์ฃผ์–ด์กŒ www.acmicpc.net ๋ฌธ์ œ ์œ„์˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ์œก๊ฐํ˜•์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฒŒ์ง‘์ด ์žˆ๋‹ค. ๊ทธ๋ฆผ์—์„œ ๋ณด๋Š” ๋ฐ”์™€ ๊ฐ™์ด ์ค‘์•™์˜ ๋ฐฉ 1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ์ด์›ƒํ•˜๋Š” ๋ฐฉ์— ๋Œ์•„๊ฐ€๋ฉด์„œ 1์”ฉ ์ฆ๊ฐ€ํ•˜๋Š” ๋ฒˆํ˜ธ๋ฅผ ์ฃผ์†Œ๋กœ ๋งค๊ธธ ์ˆ˜ ์žˆ๋‹ค. ์ˆซ์ž N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋ฒŒ์ง‘์˜ ์ค‘์•™ 1์—์„œ N๋ฒˆ ๋ฐฉ๊นŒ์ง€ ์ตœ์†Œ ๊ฐœ์ˆ˜์˜ ๋ฐฉ์„ ์ง€๋‚˜์„œ ๊ฐˆ ๋•Œ ๋ช‡ ๊ฐœ์˜ ๋ฐฉ์„ ์ง€๋‚˜๊ฐ€๋Š”์ง€(์‹œ์ž‘๊ณผ ๋์„ ํฌํ•จํ•˜์—ฌ)๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด, 13๊นŒ์ง€๋Š” 3๊ฐœ, 58๊นŒ์ง€๋Š” 5๊ฐœ๋ฅผ ์ง€๋‚œ๋‹ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์—..

[BOJ/Step8] 1712 : ์†์ต๋ถ„๊ธฐ์  (JAVA)

www.acmicpc.net/problem/1712 1712๋ฒˆ: ์†์ต๋ถ„๊ธฐ์  ์›”๋“œ์ „์ž๋Š” ๋…ธํŠธ๋ถ์„ ์ œ์กฐํ•˜๊ณ  ํŒ๋งคํ•˜๋Š” ํšŒ์‚ฌ์ด๋‹ค. ๋…ธํŠธ๋ถ ํŒ๋งค ๋Œ€์ˆ˜์— ์ƒ๊ด€์—†์ด ๋งค๋…„ ์ž„๋Œ€๋ฃŒ, ์žฌ์‚ฐ์„ธ, ๋ณดํ—˜๋ฃŒ, ๊ธ‰์—ฌ ๋“ฑ A๋งŒ์›์˜ ๊ณ ์ • ๋น„์šฉ์ด ๋“ค๋ฉฐ, ํ•œ ๋Œ€์˜ ๋…ธํŠธ๋ถ์„ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ์—๋Š” ์žฌ๋ฃŒ๋น„์™€ www.acmicpc.net ๋ฌธ์ œ ์›”๋“œ์ „์ž๋Š” ๋…ธํŠธ๋ถ์„ ์ œ์กฐํ•˜๊ณ  ํŒ๋งคํ•˜๋Š” ํšŒ์‚ฌ์ด๋‹ค. ๋…ธํŠธ๋ถ ํŒ๋งค ๋Œ€์ˆ˜์— ์ƒ๊ด€์—†์ด ๋งค๋…„ ์ž„๋Œ€๋ฃŒ, ์žฌ์‚ฐ์„ธ, ๋ณดํ—˜๋ฃŒ, ๊ธ‰์—ฌ ๋“ฑ A๋งŒ์›์˜ ๊ณ ์ • ๋น„์šฉ์ด ๋“ค๋ฉฐ, ํ•œ ๋Œ€์˜ ๋…ธํŠธ๋ถ์„ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ์—๋Š” ์žฌ๋ฃŒ๋น„์™€ ์ธ๊ฑด๋น„ ๋“ฑ ์ด B๋งŒ์›์˜ ๊ฐ€๋ณ€ ๋น„์šฉ์ด ๋“ ๋‹ค๊ณ  ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด A=1,000, B=70์ด๋ผ๊ณ  ํ•˜์ž. ์ด ๊ฒฝ์šฐ ๋…ธํŠธ๋ถ์„ ํ•œ ๋Œ€ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ๋Š” ์ด 1,070๋งŒ์›์ด ๋“ค๋ฉฐ, ์—ด ๋Œ€ ์ƒ์‚ฐํ•˜๋Š” ๋ฐ๋Š” ์ด 1,700๋งŒ์›์ด ๋“ ๋‹ค. ๋…ธํŠธ๋ถ ๊ฐ€๊ฒฉ..

[JAVA] indexOf() / lastIndexOf() ๋ฉ”์†Œ๋“œ

docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/String.html#indexOf(int) String (Java SE 15 & JDK 15) All Implemented Interfaces: Serializable, CharSequence, Comparable , Constable, ConstantDesc public final class String extends Object implements Serializable, Comparable , CharSequence, Constable, ConstantDesc The String class represents character strings. docs.oracle.com docs.ora..

[JAVA] contains() ๋ฉ”์†Œ๋“œ

docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/String.html#contains(java.lang.CharSequence) String (Java SE 15 & JDK 15) All Implemented Interfaces: Serializable, CharSequence, Comparable , Constable, ConstantDesc public final class String extends Object implements Serializable, Comparable , CharSequence, Constable, ConstantDesc The String class represents character strings. docs..