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

Algorithm242

[Codeforces] 721A: One-dimensional Japanese Crossword https://codeforces.com/problemset/problem/721/A Problem - 721A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); String str = scan.next(); int blackCount = 0;// ์—ฐ์†๋œ ๊ฒ€์ • ์‚ฌ๊ฐํ˜•์˜ ํ›„ List list = new ArrayList(); for(int i=0; i 2020. 3. 13.
[๋ฐฑ์ค€] 1057๋ฒˆ: ํ† ๋„ˆ๋จผํŠธ(๊ตฌํ˜„, ์ˆ˜ํ•™) https://www.acmicpc.net/problem/1057 1057๋ฒˆ: ํ† ๋„ˆ๋จผํŠธ ๊น€์ง€๋ฏผ์€ N๋ช…์ด ์ฐธ๊ฐ€ํ•˜๋Š” ์Šคํƒ€ ํ† ๋„ˆ๋จผํŠธ์— ์ง„์ถœํ–ˆ๋‹ค. ํ† ๋„ˆ๋จผํŠธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ง„ํ–‰๋œ๋‹ค. ์ผ๋‹จ N๋ช…์˜ ์ฐธ๊ฐ€์ž๋Š” ๋ฒˆํ˜ธ๊ฐ€ 1๋ฒˆ๋ถ€ํ„ฐ N๋ฒˆ๊นŒ์ง€ ๋ฐฐ์ •๋ฐ›๋Š”๋‹ค. ๊ทธ๋Ÿฌ๊ณ  ๋‚œ ํ›„์— ์„œ๋กœ ์ธ์ ‘ํ•œ ๋ฒˆํ˜ธ๋ผ๋ฆฌ ์Šคํƒ€๋ฅผ ํ•œ๋‹ค. ์ด๊ธด ์‚ฌ๋žŒ์€ ๋‹ค์Œ ๋ผ์šด๋“œ์— ์ง„์ถœํ•˜๊ณ , ์ง„ ์‚ฌ๋žŒ์€ ๊ทธ ๋ผ์šด๋“œ์—์„œ ๋–จ์–ด์ง„๋‹ค. ๋งŒ์•ฝ ๊ทธ ๋ผ์šด๋“œ์˜ ์ฐธ๊ฐ€์ž๊ฐ€ ํ™€์ˆ˜๋ช…์ด๋ผ๋ฉด, ๋งˆ์ง€๋ง‰ ๋ฒˆํ˜ธ๋ฅผ ๊ฐ€์ง„ ์ฐธ๊ฐ€์ž๋Š” ๋‹ค์Œ ๋ผ์šด๋“œ๋กœ ์ž๋™ ์ง„์ถœํ•œ๋‹ค. ๋‹ค์Œ ๋ผ์šด๋“œ์—์„  ๋‹ค์‹œ ์ฐธ๊ฐ€์ž์˜ ๋ฒˆํ˜ธ๋ฅผ 1๋ฒˆ๋ถ€ํ„ฐ ๋งค๊ธด๋‹ค. ์ด๋•Œ, ๋ฒˆํ˜ธ๋ฅผ ๋งค๊ธฐ๋Š” ์ˆœ์„œ๋Š” ์ฒ˜์Œ www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(Str.. 2020. 3. 12.
[๋ฐฑ์ค€] 2979๋ฒˆ: ํŠธ๋Ÿญ ์ฃผ์ฐจ(๊ตฌํ˜„, ์‹œ๋ฎฌ๋ ˆ์ด์…˜) https://www.acmicpc.net/problem/2979 2979๋ฒˆ: ํŠธ๋Ÿญ ์ฃผ์ฐจ ๋ฌธ์ œ ์ƒ๊ทผ์ด๋Š” ํŠธ๋Ÿญ์„ ์ด ์„ธ ๋Œ€ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์˜ค๋Š˜์€ ํŠธ๋Ÿญ์„ ์ฃผ์ฐจํ•˜๋Š”๋ฐ ๋น„์šฉ์ด ์–ผ๋งˆ๋‚˜ ํ•„์š”ํ•œ์ง€ ์•Œ์•„๋ณด๋ ค๊ณ  ํ•œ๋‹ค. ์ƒ๊ทผ์ด๊ฐ€ ์ด์šฉํ•˜๋Š” ์ฃผ์ฐจ์žฅ์€ ์ฃผ์ฐจํ•˜๋Š” ํŠธ๋Ÿญ์˜ ์ˆ˜์— ๋”ฐ๋ผ์„œ ์ฃผ์ฐจ ์š”๊ธˆ์„ ํ• ์ธํ•ด ์ค€๋‹ค. ํŠธ๋Ÿญ์„ ํ•œ ๋Œ€ ์ฃผ์ฐจํ•  ๋•Œ๋Š” 1๋ถ„์— ํ•œ ๋Œ€๋‹น A์›์„ ๋‚ด์•ผ ํ•œ๋‹ค. ๋‘ ๋Œ€๋ฅผ ์ฃผ์ฐจํ•  ๋•Œ๋Š” 1๋ถ„์— ํ•œ ๋Œ€๋‹น B์›, ์„ธ ๋Œ€๋ฅผ ์ฃผ์ฐจํ•  ๋•Œ๋Š” 1๋ถ„์— ํ•œ ๋Œ€๋‹น C์›์„ ๋‚ด์•ผ ํ•œ๋‹ค. A, B, C๊ฐ€ ์ฃผ์–ด์ง€๊ณ , ์ƒ๊ทผ์ด์˜ ํŠธ๋Ÿญ์ด ์ฃผ์ฐจ์žฅ์— ์ฃผ์ฐจ๋œ ์‹œ๊ฐ„์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ฃผ์ฐจ ์š”๊ธˆ์œผ๋กœ ์–ผ๋งˆ www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.i.. 2020. 3. 12.
[๋ฐฑ์ค€] 1911๋ฒˆ: ํ™๊ธธ ๋ณด์ˆ˜ํ•˜๊ธฐ(๊ทธ๋ฆฌ๋””) https://www.acmicpc.net/problem/1911 1911๋ฒˆ: ํ™๊ธธ ๋ณด์ˆ˜ํ•˜๊ธฐ ์–ด์ ฏ๋ฐค ๊ฒจ์šธ ์บ ํ”„ ์žฅ์†Œ์—์„œ ์›”๋“œ ๋ณธ์›๊นŒ์ง€ ์ด์–ด์ง€๋Š”, ํ™์œผ๋กœ ๋œ ๋น„๋ฐ€๊ธธ ์œ„์— ํญ์šฐ๊ฐ€ ๋‚ด๋ ค์„œ N (1 range) { range += L; nulpan ++; } } } System.out.println(nulpan); bf.close(); } } ํ’€์ด ์ผ๋‹จ ๊ทธ๋ฆฌ๋”” ๋ฌธ์ œ์—ฌ์„œ ํ•˜๋‚˜ํ•˜๋‚˜ ํƒ์š•์Šค๋Ÿฝ๊ฒŒ ์ ‘๊ทผํ• ๊ฑฐ๊ธฐ ๋•Œ๋ฌธ์—, ์ฃผ์–ด์ง„ ๋ฌผ ์›…๋ฉ์ด์˜ ์‹œ์ž‘์œ„์น˜, ๋์œ„์น˜๋ฅผ ์ •๋ ฌ์„ ํ•ด์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์„ ํ–ˆ๋‹ค. ์ •๋ ฌ ์กฐ๊ฑด์€ ๋ฌผ ์›…๋ฉ์ด์˜ ์‹œ์ž‘ ์œ„์น˜๊ฐ€ ๊ฐ€์žฅ ์ž‘์€ ๊ฒƒ ๋ถ€ํ„ฐ, ๊ฐ™์œผ๋ฉด ๋์œ„์น˜๊ฐ€ ์ž‘์€๊ฒƒ๋ถ€ํ„ฐ ์ •๋ ฌํ–ˆ๋‹ค. Comparator ์ธํ„ฐํŽ˜์ด์Šค ์ฐธ๊ณ  ๊ทธ ํ›„, ํ•˜๋‚˜ํ•˜๋‚˜ ๋น„๊ตํ•ด๊ฐ€๋ฉฐ ๋„๋นค์ง€๋ฅผ ์„ค์น˜ํ•  ๊ฒƒ์ธ์ง€? ์„ค์น˜ํ•œ๋‹ค๋ฉด ๋ช‡๊ฐœ์„ค์น˜ํ•˜๋Š”์ง€ ํŒ๋‹จ์„ ํ•˜๋ฉด ๋˜๋Š”๋ฐ ์—ฌ๊ธฐ์„œ.. 2020. 3. 12.
[Codeforces] 1311A: Add Odd or Subtract Even https://codeforces.com/problemset/problem/1311/A Problem - 1311A - 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; tcb) ans = ((a-b) % 2 == 0) ? 1 : 2; else ans = ((b-a) % 2 == 0) ? 2 : 1; System.out.println(ans); } scan.close(); } } ํ’€์ด ๋ฌธ์ œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. a, b.. 2020. 3. 12.
[Codeforces] 1003A: Polycarp's Pockets https://codeforces.com/problemset/problem/1003/A Problem - 1003A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] arr = new int[n]; int[] value = new int[101]; for(int i=0; i 2020. 3. 11.
[๋ฐฑ์ค€] 11729๋ฒˆ: ํ•˜๋…ธ์ด ํƒ‘ ์ด๋™ ์ˆœ์„œ(์žฌ๊ท€, ๋ถ„ํ• ์ •๋ณต) https://www.acmicpc.net/problem/11729 11729๋ฒˆ: ํ•˜๋…ธ์ด ํƒ‘ ์ด๋™ ์ˆœ์„œ ์„ธ ๊ฐœ์˜ ์žฅ๋Œ€๊ฐ€ ์žˆ๊ณ  ์ฒซ ๋ฒˆ์งธ ์žฅ๋Œ€์—๋Š” ๋ฐ˜๊ฒฝ์ด ์„œ๋กœ ๋‹ค๋ฅธ n๊ฐœ์˜ ์›ํŒ์ด ์Œ“์—ฌ ์žˆ๋‹ค. ๊ฐ ์›ํŒ์€ ๋ฐ˜๊ฒฝ์ด ํฐ ์ˆœ์„œ๋Œ€๋กœ ์Œ“์—ฌ์žˆ๋‹ค. ์ด์ œ ์ˆ˜๋„์Šน๋“ค์ด ๋‹ค์Œ ๊ทœ์น™์— ๋”ฐ๋ผ ์ฒซ ๋ฒˆ์งธ ์žฅ๋Œ€์—์„œ ์„ธ ๋ฒˆ์งธ ์žฅ๋Œ€๋กœ ์˜ฎ๊ธฐ๋ ค ํ•œ๋‹ค. ํ•œ ๋ฒˆ์— ํ•œ ๊ฐœ์˜ ์›ํŒ๋งŒ์„ ๋‹ค๋ฅธ ํƒ‘์œผ๋กœ ์˜ฎ๊ธธ ์ˆ˜ ์žˆ๋‹ค. ์Œ“์•„ ๋†“์€ ์›ํŒ์€ ํ•ญ์ƒ ์œ„์˜ ๊ฒƒ์ด ์•„๋ž˜์˜ ๊ฒƒ๋ณด๋‹ค ์ž‘์•„์•ผ ํ•œ๋‹ค. ์ด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ์ด๋™ ์ˆœ์„œ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ. ๋‹จ, ์ด๋™ ํšŸ์ˆ˜๋Š” ์ตœ์†Œ๊ฐ€ ๋˜์–ด์•ผ ํ•œ๋‹ค. ์•„๋ž˜ ๊ทธ๋ฆผ์€ ์›ํŒ์ด 5 www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { static StringBuild.. 2020. 3. 11.
[Codeforces] 978B: File Name https://codeforces.com/problemset/problem/978/B Problem - 978B - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); String str = scan.next(); int delete = 0; // ๋ฌธ์ž์—ด์—์„œ "xxx"๊ฐ€ ์žˆ์„๋•Œ => delete ํ•œ๊ฐœ์”ฉ ์ฆ๊ฐ€. for(int i=0; i 2020. 3. 11.
[๋ฐฑ์ค€] 17478๋ฒˆ: ์žฌ๊ท€ํ•จ์ˆ˜๊ฐ€ ๋ญ”๊ฐ€์š”?(์žฌ๊ท€) https://www.acmicpc.net/problem/17478 17478๋ฒˆ: ์žฌ๊ท€ํ•จ์ˆ˜๊ฐ€ ๋ญ”๊ฐ€์š”? ํ‰์†Œ์— ์งˆ๋ฌธ์„ ์ž˜ ๋ฐ›์•„์ฃผ๊ธฐ๋กœ ์œ ๋ช…ํ•œ ์ค‘์•™๋Œ€ํ•™๊ต์˜ JH ๊ต์ˆ˜๋‹˜์€ ํ•™์ƒ๋“ค๋กœ๋ถ€ํ„ฐ ์žฌ๊ท€ํ•จ์ˆ˜๊ฐ€ ๋ฌด์—‡์ธ์ง€์— ๋Œ€ํ•˜์—ฌ ๋งŽ์€ ์งˆ๋ฌธ์„ ๋ฐ›์•„์™”๋‹ค. ๋งค๋ฒˆ ์งˆ๋ฌธ์„ ์ž˜ ๋ฐ›์•„์ฃผ์…จ๋˜ JH ๊ต์ˆ˜๋‹˜์ด์ง€๋งŒ ๊ทธ๋Š” ์ค‘์•™๋Œ€ํ•™๊ต๊ฐ€ ์ž์‹ ๊ณผ ๋งž๋Š”๊ฐ€์— ๋Œ€ํ•œ ๊ณ ๋ฏผ์„ ํ•ญ์ƒ ํ•ด์™”๋‹ค. ์ค‘์•™๋Œ€ํ•™๊ต์™€ ์ž์‹ ์˜ ๊ธธ์ด ๋งž์ง€ ์•Š๋‹ค๊ณ  ์ƒ๊ฐํ•œ JH ๊ต์ˆ˜๋‹˜์€ ๊ฒฐ๊ตญ ์ค‘์•™๋Œ€ํ•™๊ต๋ฅผ ๋– ๋‚˜๊ธฐ๋กœ ๊ฒฐ์ •ํ•˜์˜€๋‹ค. ๋– ๋‚˜๊ธฐ ์ „๊นŒ์ง€๋„ ์ œ์ž๋“ค์„ ์ƒ๊ฐํ•˜์…จ๋˜ JH ๊ต์ˆ˜๋‹˜์€ ์žฌ๊ท€ํ•จ์ˆ˜๊ฐ€ ๋ฌด์—‡์ธ์ง€ ๋ฌผ์–ด๋ณด๋Š” ํ•™์ƒ๋“ค์„ ์œ„ํ•œ ์ž‘์€ ์„ ๋ฌผ๋กœ ์ž๋™ ์‘๋‹ต ์ฑ—๋ด‡์„ ์ค€๋น„ www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { static String under.. 2020. 3. 10.
[Codeforces] 1207A: There Are Two Types Of Burgers https://codeforces.com/problemset/problem/1207/A Problem - 1207A - Codeforces codeforces.com ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = .. 2020. 3. 10.
๋ฐ˜์‘ํ˜•