๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

IT Blog404

[๋ฐฑ์ค€] 2246๋ฒˆ: ์ฝ˜๋„ ์„ ์ •(๊ตฌํ˜„) https://www.acmicpc.net/problem/2246 2246๋ฒˆ: ์ฝ˜๋„ ์„ ์ • ๋ฌธ์ œ ์ฝ˜๋„๋ฅผ ์„ ์ •ํ•  ๋•Œ์—๋Š” ๊ฐ€๊ธ‰์ ์ด๋ฉด ์‹ธ๊ณ  ๋ฐ”๋‹ท๊ฐ€์— ๊ฐ€๊นŒ์šด ๊ณณ์œผ๋กœ ํ•˜๋ ค ํ•œ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด ์šฐ์„  ์ ๋‹นํ•œ ์ฝ˜๋„ ๋ช‡ ๊ณณ์„ ํ›„๋ณด๋กœ ์„ ์ •ํ•˜๋ ค ํ•˜๋Š”๋ฐ, ๋‹ค์Œ ๋‘ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์ฝ˜๋„ X๊ฐ€ ํ›„๋ณด๊ฐ€ ๋œ๋‹ค. X๋ณด๋‹ค ๋ฐ”๋‹ท๊ฐ€์— ๋” ๊ฐ€๊นŒ์šด ์ฝ˜๋„๋“ค์€ ๋ชจ๋‘ X๋ณด๋‹ค ์ˆ™๋ฐ•๋น„๊ฐ€ ๋” ๋น„์‹ธ๋‹ค. X๋ณด๋‹ค ์ˆ™๋ฐ•๋น„๊ฐ€ ๋” ์‹ผ ์ฝ˜๋„๋“ค์€ ๋ชจ๋‘ X๋ณด๋‹ค ๋ฐ”๋‹ท๊ฐ€์—์„œ ๋” ๋ฉ€๋‹ค. ๊ฐ ์ฝ˜๋„์˜ ๋ฐ”๋‹ท๊ฐ€์—์„œ์˜ ๊ฑฐ๋ฆฌ์™€ ์ˆ™๋ฐ•๋น„์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ํ›„๋ณด ์ฝ˜๋„์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•ด๋‚ด๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…๋ ฅ ์ฒซ์งธ ์ค„ www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.BufferedWriter; import jav.. 2020. 4. 9.
[Codeforces] 1080A: Petya and Origami https://codeforces.com/problemset/problem/1080/A Problem - 1080A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); /* * n๋ช…์˜ ์นœ๊ตฌ๋“ค ์ดˆ๋Œ€ํ•˜๋Š”๋ฐ ์นœ๊ตฌ๋งˆ๋‹ค 2๊ฐœ์˜ red, 5๊ฐœ์˜ green, 8๊ฐœ์˜ blue ์ข…์ด๊ฐ€ ํ•„์š”ํ•˜๋‹ค. * ์ƒ์ ์—์„  ์ข…์ด๋ฅผ ํŒ๋งคํ•˜๋Š”๋ฐ ํ•œ ์ƒ‰์ƒ์”ฉ ํŒ๋งคํ•˜๊ณ , ๊ฐ ์ƒ‰์ƒ์˜ ๊ฐฏ์ˆ˜๋Š” k๊ฐœ ์ด๋‹ค. * red๊ฐ€ 10๊ฐœํ•„์š”ํ•˜๊ณ , k๊ฐ€ 3์ผ๊ฒฝ์šฐ -> 3๊ฐœ์”ฉ 4๋ฒˆ์„ ์‚ฌ์•ผ ๋ชจ๋“  ์นœ๊ตฌ๋ฅผ ์ดˆ๋Œ€ํ•  ์ˆ˜ ์žˆ๋‹ค. */ int n = s.. 2020. 4. 9.
[๋ฐฑ์ค€] 14502๋ฒˆ: ์—ฐ๊ตฌ์†Œ(DFS, BFS, ์™„์ „ํƒ์ƒ‰) https://www.acmicpc.net/problem/14502 14502๋ฒˆ: ์—ฐ๊ตฌ์†Œ ์ธ์ฒด์— ์น˜๋ช…์ ์ธ ๋ฐ”์ด๋Ÿฌ์Šค๋ฅผ ์—ฐ๊ตฌํ•˜๋˜ ์—ฐ๊ตฌ์†Œ์—์„œ ๋ฐ”์ด๋Ÿฌ์Šค๊ฐ€ ์œ ์ถœ๋˜์—ˆ๋‹ค. ๋‹คํ–‰ํžˆ ๋ฐ”์ด๋Ÿฌ์Šค๋Š” ์•„์ง ํผ์ง€์ง€ ์•Š์•˜๊ณ , ๋ฐ”์ด๋Ÿฌ์Šค์˜ ํ™•์‚ฐ์„ ๋ง‰๊ธฐ ์œ„ํ•ด์„œ ์—ฐ๊ตฌ์†Œ์— ๋ฒฝ์„ ์„ธ์šฐ๋ ค๊ณ  ํ•œ๋‹ค. ์—ฐ๊ตฌ์†Œ๋Š” ํฌ๊ธฐ๊ฐ€ N×M์ธ ์ง์‚ฌ๊ฐํ˜•์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ง์‚ฌ๊ฐํ˜•์€ 1×1 ํฌ๊ธฐ์˜ ์ •์‚ฌ๊ฐํ˜•์œผ๋กœ ๋‚˜๋ˆ„์–ด์ ธ ์žˆ๋‹ค. ์—ฐ๊ตฌ์†Œ๋Š” ๋นˆ ์นธ, ๋ฒฝ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๋ฒฝ์€ ์นธ ํ•˜๋‚˜๋ฅผ ๊ฐ€๋“ ์ฐจ์ง€ํ•œ๋‹ค. ์ผ๋ถ€ ์นธ์€ ๋ฐ”์ด๋Ÿฌ์Šค๊ฐ€ ์กด์žฌํ•˜๋ฉฐ, ์ด ๋ฐ”์ด๋Ÿฌ์Šค๋Š” ์ƒํ•˜์ขŒ์šฐ๋กœ ์ธ์ ‘ํ•œ ๋นˆ ์นธ์œผ๋กœ ๋ชจ๋‘ ํผ์ ธ๋‚˜๊ฐˆ ์ˆ˜ ์žˆ๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io... 2020. 4. 8.
[๋ฐฑ์ค€] 1188๋ฒˆ: ์Œ์‹ํ‰๋ก ๊ฐ€(๊ตฌํ˜„, ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜) https://www.acmicpc.net/problem/1188 1188๋ฒˆ: ์Œ์‹ ํ‰๋ก ๊ฐ€ ๋ฌธ์ œ ์„ ์˜์ด์˜ ์ง์—…์€ ์†Œ์‹œ์ง€ ์š”๋ฆฌ์‚ฌ์ด๋‹ค. ์†Œ์‹œ์ง€๋ฅผ ํŒ”๊ธฐ ์ „์— ์Œ์‹ ํ‰๋ก ๊ฐ€ M๋ช…์„ ๋ชจ์•„์„œ ๋ง›์„ ํ…Œ์ŠคํŠธํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค. ์„ ์˜์ด๋Š” ๋™์ผํ•œ ์†Œ์‹œ์ง€๋ฅผ ์ด N๊ฐœ๋ฅผ ์ค€๋น„ํ–ˆ๋‹ค. ์ด ์†Œ์‹œ์ง€๋ฅผ ๋ชจ๋“  ํ‰๋ก ๊ฐ€๋“ค์ด ๊ฐ™์€ ์–‘์„ ๋ฐ›๊ฒŒ ์†Œ์‹œ์ง€๋ฅผ ์ž๋ฅด๋ ค๊ณ  ํ•œ๋‹ค. ์ด๋•Œ, ์†Œ์‹œ์ง€๋ฅผ ์ž๋ฅด๋Š” ํšŸ์ˆ˜๋ฅผ ์ตœ์†Œ๋กœ ํ•˜๋ ค๊ณ  ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์†Œ์‹œ์ง€๊ฐ€ 2๊ฐœ, ํ‰๋ก ๊ฐ€๊ฐ€ 6๋ช…์žˆ๋Š” ๊ฒฝ์šฐ๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž. ์ด๋•Œ, ๊ฐ ์†Œ์‹œ์ง€๋ฅผ ์„ธ ์กฐ๊ฐ์œผ๋กœ ๋งŒ๋“  ๋‹ค์Œ, ๊ฐ ํ‰๋ก ๊ฐ€์—๊ฒŒ ํ•œ ์กฐ๊ฐ์”ฉ ์ฃผ๋ฉด ๋œ๋‹ค. ์ด ๊ฒฝ์šฐ์— ์†Œ์‹œ์ง€๋Š” ์ด ๋„ค www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { public static int GCD(int .. 2020. 4. 8.
[Codeforces] 1316A: Grade Allocation https://codeforces.com/problemset/problem/1316/A Problem - 1316A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for(int tc=0; tc 2020. 4. 7.
[๋ฐฑ์ค€] 10709๋ฒˆ: ๊ธฐ์ƒ์บ์Šคํ„ฐ(๊ตฌํ˜„) https://www.acmicpc.net/problem/10709 10709๋ฒˆ: ๊ธฐ์ƒ์บ์Šคํ„ฐ ๋ฌธ์ œ JOI์‹œ๋Š” ๋‚จ๋ถ๋ฐฉํ–ฅ์ด H ํ‚ฌ๋กœ๋ฏธํ„ฐ, ๋™์„œ๋ฐฉํ–ฅ์ด W ํ‚ฌ๋กœ๋ฏธํ„ฐ์ธ ์ง์‚ฌ๊ฐํ˜• ๋ชจ์–‘์ด๋‹ค. JOI์‹œ๋Š” ๊ฐ€๋กœ์™€ ์„ธ๋กœ์˜ ๊ธธ์ด๊ฐ€ 1ํ‚ฌ๋กœ๋ฏธํ„ฐ์ธ H × W ๊ฐœ์˜ ์ž‘์€ ๊ตฌ์—ญ๋“ค๋กœ ๋‚˜๋‰˜์–ด ์žˆ๋‹ค. ๋ถ์ชฝ์œผ๋กœ๋ถ€ํ„ฐ i ๋ฒˆ์งธ, ์„œ์ชฝ์œผ๋กœ๋ถ€ํ„ฐ j ๋ฒˆ์งธ์— ์žˆ๋Š” ๊ตฌ์—ญ์„ (i, j) ๋กœ ํ‘œ์‹œํ•œ๋‹ค. ๊ฐ ๊ตฌ์—ญ์˜ ํ•˜๋Š˜์—๋Š” ๊ตฌ๋ฆ„์ด ์žˆ์„ ์ˆ˜๋„, ์—†์„ ์ˆ˜๋„ ์žˆ๋‹ค. ๋ชจ๋“  ๊ตฌ๋ฆ„์€ 1๋ถ„์ด ์ง€๋‚  ๋•Œ๋งˆ๋‹ค 1ํ‚ฌ๋กœ๋ฏธํ„ฐ์”ฉ ๋™์ชฝ์œผ๋กœ ์ด๋™ํ•œ๋‹ค. ์˜ค๋Š˜์€ ๋‚ ์”จ๊ฐ€ ์ •๋ง ์ข‹๊ธฐ ๋•Œ๋ฌธ์— JOI์‹œ์˜ ์™ธ๋ถ€์—์„œ ๊ตฌ๋ฆ„์ด ์ด๋™ํ•ด ์˜ค๋Š” ๊ฒฝ์šฐ www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.BufferedWriter; import j.. 2020. 4. 7.
[๋ฐฑ์ค€] 1021๋ฒˆ: ํšŒ์ „ํ•˜๋Š” ํ https://www.acmicpc.net/problem/1021 1021๋ฒˆ: ํšŒ์ „ํ•˜๋Š” ํ ์ฒซ์งธ ์ค„์— ํ์˜ ํฌ๊ธฐ N๊ณผ ๋ฝ‘์•„๋‚ด๋ ค๊ณ  ํ•˜๋Š” ์ˆ˜์˜ ๊ฐœ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , M์€ N๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ง€๋ฏผ์ด๊ฐ€ ๋ฝ‘์•„๋‚ด๋ ค๊ณ  ํ•˜๋Š” ์ˆ˜์˜ ์œ„์น˜๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. ์œ„์น˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , N๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.StringTokenizer; public class Main.. 2020. 4. 7.
[๋ฐฑ์ค€] 10026๋ฒˆ: ์ ๋ก์ƒ‰์•ฝ(DFS) https://www.acmicpc.net/problem/10026 10026๋ฒˆ: ์ ๋ก์ƒ‰์•ฝ ๋ฌธ์ œ ์ ๋ก์ƒ‰์•ฝ์€ ๋นจ๊ฐ„์ƒ‰๊ณผ ์ดˆ๋ก์ƒ‰์˜ ์ฐจ์ด๋ฅผ ๊ฑฐ์˜ ๋Š๋ผ์ง€ ๋ชปํ•œ๋‹ค. ๋”ฐ๋ผ์„œ, ์ ๋ก์ƒ‰์•ฝ์ธ ์‚ฌ๋žŒ์ด ๋ณด๋Š” ๊ทธ๋ฆผ์€ ์•„๋‹Œ ์‚ฌ๋žŒ์ด ๋ณด๋Š” ๊ทธ๋ฆผ๊ณผ๋Š” ์ข€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค. ํฌ๊ธฐ๊ฐ€ N×N์ธ ๊ทธ๋ฆฌ๋“œ์˜ ๊ฐ ์นธ์— R(๋นจ๊ฐ•), G(์ดˆ๋ก), B(ํŒŒ๋ž‘) ์ค‘ ํ•˜๋‚˜๋ฅผ ์ƒ‰์น ํ•œ ๊ทธ๋ฆผ์ด ์žˆ๋‹ค. ๊ทธ๋ฆผ์€ ๋ช‡ ๊ฐœ์˜ ๊ตฌ์—ญ์œผ๋กœ ๋‚˜๋‰˜์–ด์ ธ ์žˆ๋Š”๋ฐ, ๊ตฌ์—ญ์€ ๊ฐ™์€ ์ƒ‰์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๋˜, ๊ฐ™์€ ์ƒ‰์ƒ์ด ์ƒํ•˜์ขŒ์šฐ๋กœ ์ธ์ ‘ํ•ด ์žˆ๋Š” ๊ฒฝ์šฐ์— ๋‘ ๊ธ€์ž๋Š” ๊ฐ™์€ ๊ตฌ์—ญ์— ์†ํ•œ๋‹ค. (์ƒ‰์ƒ์˜ ์ฐจ์ด๋ฅผ ๊ฑฐ์˜ ๋Š๋ผ์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ๋„ ๊ฐ™์€ www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.i.. 2020. 4. 6.
[Codeforces] 1136A: Nastya is Reading a Book https://codeforces.com/problemset/problem/1136/A Problem - 1136A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Scanner; public class A1136 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); // ์ฑ•ํ„ฐ ์ˆ˜ int[][] arr = new int[n][2]; // ์ฑ•ํ„ฐ๋‹น ํŽ˜์ด์ง€ ๋ฒ”์œ„ for(int i=0; i 2020. 4. 6.
[Codeforces] 1093A: Dice Rolling https://codeforces.com/problemset/problem/1093/A Problem - 1093A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); int count = 0;// roll ๊ฐฏ์ˆ˜ for(int tc=0; tc 2020. 4. 2.
๋ฐ˜์‘ํ˜•