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

Algorithm242

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก(ํ•ด์‹œ) https://programmers.co.kr/learn/courses/30/lessons/42577 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ „ํ™”๋ฒˆํ˜ธ๋ถ€์— ์ ํžŒ ์ „ํ™”๋ฒˆํ˜ธ ์ค‘, ํ•œ ๋ฒˆํ˜ธ๊ฐ€ ๋‹ค๋ฅธ ๋ฒˆํ˜ธ์˜ ์ ‘๋‘์–ด์ธ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค. ์ „ํ™”๋ฒˆํ˜ธ๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์„ ๊ฒฝ์šฐ, ๊ตฌ์กฐ๋Œ€ ์ „ํ™”๋ฒˆํ˜ธ๋Š” ์˜์„์ด์˜ ์ „ํ™”๋ฒˆํ˜ธ์˜ ์ ‘๋‘์‚ฌ์ž…๋‹ˆ๋‹ค. ๊ตฌ์กฐ๋Œ€ : 119 ๋ฐ•์ค€์˜ : 97 674 223 ์ง€์˜์„ : 11 9552 4421 ์ „ํ™”๋ฒˆํ˜ธ๋ถ€์— ์ ํžŒ ์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ๋‹ด์€ ๋ฐฐ์—ด phone_book ์ด solution ํ•จ์ˆ˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ์–ด๋–ค ๋ฒˆํ˜ธ๊ฐ€ ๋‹ค๋ฅธ ๋ฒˆํ˜ธ์˜ ์ ‘๋‘์–ด์ธ ๊ฒฝ์šฐ๊ฐ€ ์žˆ์œผ๋ฉด false๋ฅผ ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด true๋ฅผ r programmers.co.kr ์ฝ”๋“œ class Solution { public boolean sol.. 2020. 3. 5.
[๋ฐฑ์ค€] 1748๋ฒˆ: ์ˆ˜ ์ด์–ด ์“ฐ๊ธฐ 1(๊ตฌํ˜„) https://www.acmicpc.net/problem/1748 1748๋ฒˆ: ์ˆ˜ ์ด์–ด ์“ฐ๊ธฐ 1 ์ฒซ์งธ ์ค„์— N(1≤N≤100,000,000)์ด ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int count = 0;// ์ž๋ฆฟ์ˆ˜ int plus = 1;// ์ž๋ฆฟ์ˆ˜์— ๋”ํ•˜๋Š” .. 2020. 3. 5.
[๋ฐฑ์ค€] 1912๋ฒˆ: ์—ฐ์†ํ•ฉ(DP) https://www.acmicpc.net/problem/1912 1912๋ฒˆ: ์—ฐ์†ํ•ฉ ์ฒซ์งธ ์ค„์— ์ •์ˆ˜ n(1 ≤ n ≤ 100,000)์ด ์ฃผ์–ด์ง€๊ณ  ๋‘˜์งธ ์ค„์—๋Š” n๊ฐœ์˜ ์ •์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ ์ˆ˜์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ์ˆ˜๋Š” -1,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค. www.acmicpc.net ์ฝ”๋“œ 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 =.. 2020. 3. 5.
[๋ฐฑ์ค€] 3985๋ฒˆ: ๋กค ์ผ€์ดํฌ(๊ตฌํ˜„, ์‹œ๋ฎฌ๋ ˆ์ด์…˜) https://www.acmicpc.net/problem/3985 3985๋ฒˆ: ๋กค ์ผ€์ดํฌ ๋ฌธ์ œ ์ธ๊ธฐ ํ‹ฐ๋น„ ํ”„๋กœ๊ทธ๋žจ "๋‚˜๋Š” ์š”๋ฆฌ์‚ฌ ์ธ๊ฐ€?"์˜ ์ƒˆ ์‹œ์ฆŒ์ด ์‹œ์ž‘ํ•œ๋‹ค. ์ด๋ฒˆ ์‹œ์ฆŒ์€ ๊ธฐ๋„ค์Šค๋ถ์— ๋“ฑ์žฌ๋  ๋งŒํ•œ ์Œ์‹์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ์ง„ํ–‰ํ•œ๋‹ค. ์ฒซ ๋ฒˆ์งธ ์—ํ”ผ์†Œ๋“œ์— ์ถœ์—ฐํ•˜๋Š” ์š”๋ฆฌ์‚ฌ๋Š” ์ „์„ค์˜ ์š”๋ฆฌ์‚ฌ ๊น€์ƒ๊ทผ์ด๊ณ , ๊ธธ์ด L๋ฏธํ„ฐ์˜ ๋กค ์ผ€์ดํฌ๋ฅผ ๋งŒ๋“ค ๊ฒƒ์ด๋‹ค. ์ƒ๊ทผ์€ ๋ช‡ ์‹œ๊ฐ„๋™์•ˆ ์ง‘์ค‘ํ•ด์„œ ์ผ€์ดํฌ๋ฅผ ๋งŒ๋“ค์—ˆ๊ณ , ์ด์ œ ์ŠคํŠœ๋””์˜ค์˜ ๋ฐฉ์ฒญ๊ฐ N๋ช…์—๊ฒŒ ์ผ€์ดํฌ๋ฅผ ๋‚˜๋ˆ„์–ด ์ฃผ๋ ค๊ณ  ํ•œ๋‹ค. ์ƒ๊ทผ์ด๋Š” ๋กค ์ผ€์ดํฌ๋ฅผ ํŽผ์ณ์„œ 1๋ฏธํ„ฐ ๋‹จ์œ„๋กœ ์ž˜๋ผ ๋†“์•˜๋‹ค. ๊ฐ€์žฅ ์™ผ์ชฝ ์กฐ๊ฐ์ด 1๋ฒˆ, ์˜ค๋ฅธ์ชฝ ์กฐ๊ฐ์ด www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(Str.. 2020. 3. 5.
[Codeforces] 509A: Maximum in Table https://codeforces.com/problemset/problem/509/A Problem - 509A - 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(); int[][] arr = new int[n][n]; if(n == 1) { System.out.println(1); return; } // 1ํ–‰์˜ ๊ฐ’๋“ค์€ 1 ... 0,0 ~ 0,n = 1 for(int i=0; i 2020. 3. 5.
[๋ฐฑ์ค€] 1551๋ฒˆ: ์ˆ˜์—ด์˜ ๋ณ€ํ™”(์ˆ˜ํ•™, ์‹œ๋ฎฌ๋ ˆ์ด์…˜) https://www.acmicpc.net/problem/1551 1551๋ฒˆ: ์ˆ˜์—ด์˜ ๋ณ€ํ™” ์ฒซ์งธ ์ค„์— ์ˆ˜์—ด์˜ ํฌ๊ธฐ N๊ณผ K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. N์€ 20๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , K๋Š” 0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , N-1๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ˆ˜์—ด์ด ‘,’๋กœ ๊ตฌ๋ถ„๋˜์–ด ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws I.. 2020. 3. 4.
[๋ฐฑ์ค€] 1526๋ฒˆ: ๊ฐ€์žฅ ํฐ ๊ธˆ๋ฏผ์ˆ˜(์‹œ๋ฎฌ๋ ˆ์ด์…˜) https://www.acmicpc.net/problem/1526 1526๋ฒˆ: ๊ฐ€์žฅ ํฐ ๊ธˆ๋ฏผ์ˆ˜ ์ฒซ์งธ ์ค„์— N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 4๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ  1,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); // N ๋ถ€ํ„ฐ ๋งŒ์กฑํ•˜๋Š” ์ˆ˜๊นŒ์ง€ ๊ฐ์†Œํ•˜๋ฉด์„œ ์ฐพ๋Š”๋‹ค. for(int i=N; i>=4; i--) { boolean flag = true; int num = i; while(num != 0) { // num์˜ ๋์— ์ž๋ฆฌ๊ฐ€ .. 2020. 3. 4.
[๋ฐฑ์ค€] 2563๋ฒˆ: ์ƒ‰์ข…์ด(์™„์ „ํƒ์ƒ‰, ๊ตฌํ˜„) https://www.acmicpc.net/problem/2563 2563๋ฒˆ: ์ƒ‰์ข…์ด ๊ฐ€๋กœ, ์„ธ๋กœ์˜ ํฌ๊ธฐ๊ฐ€ ๊ฐ๊ฐ 100์ธ ์ •์‚ฌ๊ฐํ˜• ๋ชจ์–‘์˜ ํฐ์ƒ‰ ๋„ํ™”์ง€๊ฐ€ ์žˆ๋‹ค. ์ด ๋„ํ™”์ง€ ์œ„์— ๊ฐ€๋กœ, ์„ธ๋กœ์˜ ํฌ๊ธฐ๊ฐ€ ๊ฐ๊ฐ 10์ธ ์ •์‚ฌ๊ฐํ˜• ๋ชจ์–‘์˜ ๊ฒ€์€์ƒ‰ ์ƒ‰์ข…์ด๋ฅผ ์ƒ‰์ข…์ด์˜ ๋ณ€๊ณผ ๋„ํ™”์ง€์˜ ๋ณ€์ด ํ‰ํ–‰ํ•˜๋„๋ก ๋ถ™์ธ๋‹ค. ์ด๋Ÿฌํ•œ ๋ฐฉ์‹์œผ๋กœ ์ƒ‰์ข…์ด๋ฅผ ํ•œ ์žฅ ๋˜๋Š” ์—ฌ๋Ÿฌ ์žฅ ๋ถ™์ธ ํ›„ ์ƒ‰์ข…์ด๊ฐ€ ๋ถ™์€ ๊ฒ€์€ ์˜์—ญ์˜ ๋„“์ด๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด ํฐ์ƒ‰ ๋„ํ™”์ง€ ์œ„์— ์„ธ ์žฅ์˜ ๊ฒ€์€์ƒ‰ ์ƒ‰์ข…์ด๋ฅผ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์€ ๋ชจ์–‘์œผ๋กœ ๋ถ™์˜€๋‹ค๋ฉด ๊ฒ€์€์ƒ‰ ์˜์—ญ์˜ ๋„“์ด๋Š” 260์ด ๋œ๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] arg.. 2020. 3. 4.
[๋ฐฑ์ค€] 1789๋ฒˆ: ์ˆ˜๋“ค์˜ ํ•ฉ(๊ตฌํ˜„) https://www.acmicpc.net/problem/1789 1789๋ฒˆ: ์ˆ˜๋“ค์˜ ํ•ฉ ์ฒซ์งธ ์ค„์— ์ž์—ฐ์ˆ˜ S(1 ≤ S ≤ 4,294,967,295)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long num = scan.nextLong(); long sum = 0; int count = 0; for(int i=1; ; i++) { if(sum > num)break; sum += i; count ++; } System.out.println(count-1); scan.close(.. 2020. 3. 4.
[๋ฐฑ์ค€] 1764๋ฒˆ: ๋“ฃ๋ณด์žก(๊ตฌํ˜„, ์ •๋ ฌ) - HashSet https://www.acmicpc.net/problem/1764 1764๋ฒˆ: ๋“ฃ๋ณด์žก ์ฒซ์งธ ์ค„์— ๋“ฃ๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์˜ ์ˆ˜ N, ๋ณด๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์˜ ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. ์ด์–ด์„œ ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ ๋“ฃ๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์˜ ์ด๋ฆ„๊ณผ, N+2์งธ ์ค„๋ถ€ํ„ฐ ๋ณด๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์˜ ์ด๋ฆ„์ด ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. ์ด๋ฆ„์€ ๋„์–ด์“ฐ๊ธฐ ์—†์ด ์˜์–ด ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง€๋ฉฐ, ๊ทธ ๊ธธ์ด๋Š” 20 ์ดํ•˜์ด๋‹ค. N, M์€ 500,000 ์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ด๋‹ค. www.acmicpc.net ํ‹€๋ฆฐ ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokeniz.. 2020. 3. 4.
๋ฐ˜์‘ํ˜•