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

IT Blog405

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ์•ผ๊ทผ ์ง€์ˆ˜ https://programmers.co.kr/learn/courses/30/lessons/12927 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์•ผ๊ทผ ์ง€์ˆ˜ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ํšŒ์‚ฌ์› Demi๋Š” ๊ฐ€๋”์€ ์•ผ๊ทผ์„ ํ•˜๋Š”๋ฐ์š”, ์•ผ๊ทผ์„ ํ•˜๋ฉด ์•ผ๊ทผ ํ”ผ๋กœ๋„๊ฐ€ ์Œ“์ž…๋‹ˆ๋‹ค. ์•ผ๊ทผ ํ”ผ๋กœ๋„๋Š” ์•ผ๊ทผ์„ ์‹œ์ž‘ํ•œ ์‹œ์ ์—์„œ ๋‚จ์€ ์ผ์˜ ์ž‘์—…๋Ÿ‰์„ ์ œ๊ณฑํ•˜์—ฌ ๋”ํ•œ ๊ฐ’์ž…๋‹ˆ๋‹ค. Demi๋Š” N์‹œ๊ฐ„ ๋™์•ˆ ์•ผ๊ทผ ํ”ผ๋กœ๋„๋ฅผ ์ตœ์†Œํ™”ํ•˜๋„๋ก ์ผํ•  ๊ฒ๋‹ˆ๋‹ค.Demi๊ฐ€ 1์‹œ๊ฐ„ ๋™์•ˆ ์ž‘์—…๋Ÿ‰ 1๋งŒํผ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•  ๋•Œ, ํ‡ด๊ทผ๊นŒ์ง€ ๋‚จ์€ N ์‹œ๊ฐ„๊ณผ ๊ฐ ์ผ์— ๋Œ€ํ•œ ์ž‘์—…๋Ÿ‰ works์— ๋Œ€ํ•ด ์•ผ๊ทผ ํ”ผ๋กœ๋„๋ฅผ ์ตœ์†Œํ™”ํ•œ ๊ฐ’์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜ solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ ์‚ฌํ•ญ works๋Š” ๊ธธ์ด programmers.co.kr ํ‹€๋ฆฐ ์ฝ”๋“œ import java.util.Arrays; class Sol.. 2020. 3. 3.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ๋‹จ์†์นด๋ฉ”๋ผ(Greedy) https://programmers.co.kr/learn/courses/30/lessons/42884 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋‹จ์†์นด๋ฉ”๋ผ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค [[-20,15], [-14,-5], [-18,-13], [-5,-3]] 2 programmers.co.kr ์ฝ”๋“œ import java.util.*; class Solution { public static int solution(int[][] routes) { int answer = 1; // 2์ฐจ์› ๋ฐฐ์—ด ์ •๋ ฌ // ์ง„์ž…์ง€์ ์„ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ -> ๊ฐ™์œผ๋ฉด ๋‚˜๊ฐ„์ง€์ ์„ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ Arrays.sort(routes, new Comparator() { @Override public int compare(int[] o1, int[] o2) { if(o1[0].. 2020. 3. 2.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ์ง์ง€์–ด ์ œ๊ฑฐํ•˜๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/12973 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ง์ง€์–ด ์ œ๊ฑฐํ•˜๊ธฐ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ง์ง€์–ด ์ œ๊ฑฐํ•˜๊ธฐ๋Š”, ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์„ ๊ฐ€์ง€๊ณ  ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๋จผ์ € ๋ฌธ์ž์—ด์—์„œ ๊ฐ™์€ ์•ŒํŒŒ๋ฒณ์ด 2๊ฐœ ๋ถ™์–ด ์žˆ๋Š” ์ง์„ ์ฐพ์Šต๋‹ˆ๋‹ค. ๊ทธ๋‹ค์Œ, ๊ทธ ๋‘˜์„ ์ œ๊ฑฐํ•œ ๋’ค, ์•ž๋’ค๋กœ ๋ฌธ์ž์—ด์„ ์ด์–ด ๋ถ™์ž…๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์„ ๋ฐ˜๋ณตํ•ด์„œ ๋ฌธ์ž์—ด์„ ๋ชจ๋‘ ์ œ๊ฑฐํ•œ๋‹ค๋ฉด ์ง์ง€์–ด ์ œ๊ฑฐํ•˜๊ธฐ๊ฐ€ ์ข…๋ฃŒ๋ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ง์ง€์–ด ์ œ๊ฑฐํ•˜๊ธฐ๋ฅผ ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”. ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์œผ๋ฉด 1์„, ์•„๋‹ ๊ฒฝ์šฐ 0์„ ๋ฆฌํ„ดํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค programmers.co.kr ํ‹€๋ฆฐ ์ฝ”๋“œ class Solution { static int sol.. 2020. 3. 2.
[๋ฐฑ์ค€] 11727๋ฒˆ: 2xn ํƒ€์ผ๋ง 2 https://www.acmicpc.net/problem/11727 11727๋ฒˆ: 2×n ํƒ€์ผ๋ง 2 ์ฒซ์งธ ์ค„์— 2×n ํฌ๊ธฐ์˜ ์ง์‚ฌ๊ฐํ˜•์„ ์ฑ„์šฐ๋Š” ๋ฐฉ๋ฒ•์˜ ์ˆ˜๋ฅผ 10,007๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. 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(); int[] dp = new int[1001]; dp[1] = 1; dp[2] = 3; for(int i=3; i dp[n-1] ๋งˆ์ง€๋ง‰ ๋„ค๋ชจ๋ฅผ 1X2 ์ง์‚ฌ๊ฐํ˜• ๋‘๊ฐœ๋กœ ๋†“๋Š” ๊ฒฝ์šฐ -> dp[n-2] ๊ทธ๋ฆฌ๊ณ  ์ถ”๊ฐ€์ ์œผ๋กœ ๋งˆ.. 2020. 3. 2.
[Codeforces] 677A: Vanya and Fence https://codeforces.com/problemset/problem/677/A Problem - 677A - 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 h = scan.nextInt(); int[] arr = new int[n]; int sum = 0; for(int i=0; i 2020. 3. 1.
[๋ฐฑ์ค€] 4641๋ฒˆ: Doubles(์™„์ „ ํƒ์ƒ‰) https://www.acmicpc.net/problem/4641 4641๋ฒˆ: Doubles ๋ฌธ์ œ 2~15๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ ์ž์—ฐ์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฆฌ์ŠคํŠธ๊ฐ€ ์žˆ์„ ๋•Œ, ์ด๋“ค ์ค‘ ๋ฆฌ์ŠคํŠธ ์•ˆ์— ์ž์‹ ์˜ ์ •ํ™•ํžˆ 2๋ฐฐ์ธ ์ˆ˜๊ฐ€ ์žˆ๋Š” ์ˆ˜์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜์—ฌ๋ผ. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฆฌ์ŠคํŠธ๊ฐ€ "1 4 3 2 9 7 18 22"๋ผ๋ฉด 2๊ฐ€ 1์˜ 2๋ฐฐ, 4๊ฐ€ 2์˜ 2๋ฐฐ, 18์ด 9์˜ 2๋ฐฐ์ด๋ฏ€๋กœ ๋‹ต์€ 3์ด๋‹ค. ์ž…๋ ฅ ์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ์ฃผ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ์ž…๋ ฅ์˜ ๋์—๋Š” -1์ด ํ•˜๋‚˜ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, 2~15๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ ์ž์—ฐ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.. 2020. 2. 29.
[๋ฐฑ์ค€] 2156๋ฒˆ: ํฌ๋„์ฃผ ์‹œ์‹(DP) https://www.acmicpc.net/problem/2156 2156๋ฒˆ: ํฌ๋„์ฃผ ์‹œ์‹ ํšจ์ฃผ๋Š” ํฌ๋„์ฃผ ์‹œ์‹ํšŒ์— ๊ฐ”๋‹ค. ๊ทธ ๊ณณ์— ๊ฐ”๋”๋‹ˆ, ํ…Œ์ด๋ธ” ์œ„์— ๋‹ค์–‘ํ•œ ํฌ๋„์ฃผ๊ฐ€ ๋“ค์–ด์žˆ๋Š” ํฌ๋„์ฃผ ์ž”์ด ์ผ๋ ฌ๋กœ ๋†“์—ฌ ์žˆ์—ˆ๋‹ค. ํšจ์ฃผ๋Š” ํฌ๋„์ฃผ ์‹œ์‹์„ ํ•˜๋ ค๊ณ  ํ•˜๋Š”๋ฐ, ์—ฌ๊ธฐ์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‘ ๊ฐ€์ง€ ๊ทœ์น™์ด ์žˆ๋‹ค. ํฌ๋„์ฃผ ์ž”์„ ์„ ํƒํ•˜๋ฉด ๊ทธ ์ž”์— ๋“ค์–ด์žˆ๋Š” ํฌ๋„์ฃผ๋Š” ๋ชจ๋‘ ๋งˆ์…”์•ผ ํ•˜๊ณ , ๋งˆ์‹  ํ›„์—๋Š” ์›๋ž˜ ์œ„์น˜์— ๋‹ค์‹œ ๋†“์•„์•ผ ํ•œ๋‹ค. ์—ฐ์†์œผ๋กœ ๋†“์—ฌ ์žˆ๋Š” 3์ž”์„ ๋ชจ๋‘ ๋งˆ์‹ค ์ˆ˜๋Š” ์—†๋‹ค. ํšจ์ฃผ๋Š” ๋  ์ˆ˜ ์žˆ๋Š” ๋Œ€๋กœ ๋งŽ์€ ์–‘์˜ ํฌ๋„์ฃผ๋ฅผ ๋ง›๋ณด๊ธฐ ์œ„ํ•ด์„œ ์–ด๋–ค ํฌ๋„์ฃผ ์ž”์„ ์„ ํƒํ•ด์•ผ ํ• ์ง€ ๊ณ  www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(S.. 2020. 2. 28.
[๋ฐฑ์ค€] 2437๋ฒˆ: ์ €์šธ(๊ทธ๋ฆฌ๋””) https://www.acmicpc.net/problem/2437 2437๋ฒˆ: ์ €์šธ ํ•˜๋‚˜์˜ ์–‘ํŒ” ์ €์šธ์„ ์ด์šฉํ•˜์—ฌ ๋ฌผ๊ฑด์˜ ๋ฌด๊ฒŒ๋ฅผ ์ธก์ •ํ•˜๋ ค๊ณ  ํ•œ๋‹ค. ์ด ์ €์šธ์˜ ์–‘ ํŒ”์˜ ๋์—๋Š” ๋ฌผ๊ฑด์ด๋‚˜ ์ถ”๋ฅผ ์˜ฌ๋ ค๋†“๋Š” ์ ‘์‹œ๊ฐ€ ๋‹ฌ๋ ค ์žˆ๊ณ , ์–‘ํŒ”์˜ ๊ธธ์ด๋Š” ๊ฐ™๋‹ค. ๋˜ํ•œ, ์ €์šธ์˜ ํ•œ์ชฝ์—๋Š” ์ €์šธ์ถ”๋“ค๋งŒ ๋†“์„ ์ˆ˜ ์žˆ๊ณ , ๋‹ค๋ฅธ ์ชฝ์—๋Š” ๋ฌด๊ฒŒ๋ฅผ ์ธก์ •ํ•˜๋ ค๋Š” ๋ฌผ๊ฑด๋งŒ ์˜ฌ๋ ค๋†“์„ ์ˆ˜ ์žˆ๋‹ค. ๋ฌด๊ฒŒ๊ฐ€ ์–‘์˜ ์ •์ˆ˜์ธ N๊ฐœ์˜ ์ €์šธ์ถ”๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ์ด ์ถ”๋“ค์„ ์‚ฌ์šฉํ•˜์—ฌ ์ธก์ •ํ•  ์ˆ˜ ์—†๋Š” ์–‘์˜ ์ •์ˆ˜ ๋ฌด๊ฒŒ ์ค‘ ์ตœ์†Ÿ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฌด๊ฒŒ๊ฐ€ ๊ฐ๊ฐ 3, 1, 6, 2, 7, 30 www.acmicpc.net ์ฝ”๋“œ import java.util.Arrays; import java.util.Scanner; public class Main { publ.. 2020. 2. 28.
[๋ฐฑ์ค€] 1236๋ฒˆ: ์„ฑ ์ง€ํ‚ค๊ธฐ(๊ตฌํ˜„) https://www.acmicpc.net/problem/1236 1236๋ฒˆ: ์„ฑ ์ง€ํ‚ค๊ธฐ ์ฒซ์งธ ์ค„์— ์„ฑ์˜ ์„ธ๋กœ ํฌ๊ธฐ N๊ณผ ๊ฐ€๋กœ ํฌ๊ธฐ M์ด ์ฃผ์–ด์ง„๋‹ค. N๊ณผ M์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ์„ฑ์˜ ์ƒํƒœ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์„ฑ์˜ ์ƒํƒœ๋Š” .์€ ๋นˆ์นธ, X๋Š” ๊ฒฝ๋น„์›์ด ์žˆ๋Š” ์นธ์ด๋‹ค. 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();// ์„ธ๋กœ int M = scan.nextInt();// ๊ฐ€๋กœ int row = 0;// ํ–‰ int col = 0;.. 2020. 2. 27.
[๋ฐฑ์ค€] 1449๋ฒˆ: ์ˆ˜๋ฆฌ๊ณต ํ•ญ์Šน(๊ทธ๋ฆฌ๋””, ์ •๋ ฌ) https://www.acmicpc.net/problem/1449 1449๋ฒˆ: ์ˆ˜๋ฆฌ๊ณต ํ•ญ์Šน ์ฒซ์งธ ์ค„์— ๋ฌผ์ด ์ƒˆ๋Š” ๊ณณ์˜ ๊ฐœ์ˆ˜ N๊ณผ ํ…Œ์ดํ”„์˜ ๊ธธ์ด L์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ๋ฌผ์ด ์ƒˆ๋Š” ๊ณณ์˜ ์œ„์น˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. N๊ณผ L์€ 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , ๋ฌผ์ด ์ƒˆ๋Š” ๊ณณ์˜ ์œ„์น˜๋Š” 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. 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(St.. 2020. 2. 27.
๋ฐ˜์‘ํ˜•