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

IT Blog405

[๋ฐฑ์ค€] 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.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ์นดํŽซ(์™„์ „ํƒ์ƒ‰, ์ˆ˜ํ•™) https://programmers.co.kr/learn/courses/30/lessons/42842 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์นดํŽซ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Leo๋Š” ์นดํŽซ์„ ์‚ฌ๋Ÿฌ ๊ฐ”๋‹ค๊ฐ€ ์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ์ค‘์•™์—๋Š” ๋นจ๊ฐ„์ƒ‰์œผ๋กœ ์น ํ•ด์ ธ ์žˆ๊ณ  ํ…Œ๋‘๋ฆฌ 1์ค„์€ ๊ฐˆ์ƒ‰์œผ๋กœ ์น ํ•ด์ ธ ์žˆ๋Š” ๊ฒฉ์ž ๋ชจ์–‘ ์นดํŽซ์„ ๋ดค์Šต๋‹ˆ๋‹ค. Leo๋Š” ์ง‘์œผ๋กœ ๋Œ์•„์™€์„œ ์•„๊นŒ ๋ณธ ์นดํŽซ์˜ ๋นจ๊ฐ„์ƒ‰๊ณผ ๊ฐˆ์ƒ‰์œผ๋กœ ์ƒ‰์น ๋œ ๊ฒฉ์ž์˜ ๊ฐœ์ˆ˜๋Š” ๊ธฐ์–ตํ–ˆ์ง€๋งŒ, ์ „์ฒด ์นดํŽซ์˜ ํฌ๊ธฐ๋Š” ๊ธฐ์–ตํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. Leo๊ฐ€ ๋ณธ ์นดํŽซ์—์„œ ๊ฐˆ์ƒ‰ ๊ฒฉ์ž์˜ ์ˆ˜ brown, ๋นจ๊ฐ„์ƒ‰ ๊ฒฉ์ž์˜ ์ˆ˜ red๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ ์นดํŽซ์˜ ๊ฐ€๋กœ, ์„ธ๋กœ ํฌ๊ธฐ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋ฐฐ์—ด์— ๋‹ด์•„ return ํ•˜๋„๋ก solution programmers.co.kr ์ฝ”๋“œ class Solution { public int[] solution(i.. 2020. 3. 4.
[๋ฐฑ์ค€] 13300๋ฒˆ: ๋ฐฉ ๋ฐฐ์ •(๊ตฌํ˜„) https://www.acmicpc.net/problem/13300 13300๋ฒˆ: ๋ฐฉ ๋ฐฐ์ • ํ‘œ์ค€ ์ž…๋ ฅ์œผ๋กœ ๋‹ค์Œ ์ •๋ณด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฒซ ๋ฒˆ์งธ ์ค„์—๋Š” ์ˆ˜ํ•™์—ฌํ–‰์— ์ฐธ๊ฐ€ํ•˜๋Š” ํ•™์ƒ ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ •์ˆ˜ N(1 ≤ N ≤ 1,000)๊ณผ ํ•œ ๋ฐฉ์— ๋ฐฐ์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ์ธ์› ์ˆ˜ K(1 < K ≤ 1,000)๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๋ถ„๋ฆฌ๋˜์–ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ N ๊ฐœ์˜ ๊ฐ ์ค„์—๋Š” ํ•™์ƒ์˜ ์„ฑ๋ณ„ S์™€ ํ•™๋…„ Y(1 ≤ Y ≤ 6)๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๋ถ„๋ฆฌ๋˜์–ด ์ฃผ์–ด์ง„๋‹ค. ์„ฑ๋ณ„ S๋Š” 0, 1์ค‘ ํ•˜๋‚˜๋กœ์„œ ์—ฌํ•™์ƒ์ธ ๊ฒฝ์šฐ์— 0, ๋‚จํ•™์ƒ์ธ ๊ฒฝ์šฐ์— 1๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค. www.acmicpc.net ์ฝ”๋“œ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; im.. 2020. 3. 4.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - K๋ฒˆ์งธ์ˆ˜(์ •๋ ฌ) https://programmers.co.kr/learn/courses/30/lessons/42748 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - K๋ฒˆ์งธ์ˆ˜ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค [1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3] programmers.co.kr ์ฝ”๋“œ import java.util.*; class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; for(int i=0; i commands[i][1] ~ commands[i][0]๊นŒ์ง€ ์ž๋ฅธ ํ›„ ์ •๋ ฌํ•˜๋ฏ€๋กœ ๋‘ ๊ฐ’ ๋นผ๊ณ  +1 int[] arr = new int[comman.. 2020. 3. 4.
[Codeforces] 703A: Mishka and Game https://codeforces.com/problemset/problem/703/A Problem - 703A - 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 Mishka = 0;// Mishak wins int Chris = 0;// Chris wins String result = ""; for(int i=0; i b) ? 1 : 0; Chris += (b > a) ? 1 : 0; } result = (Mishka > Ch.. 2020. 3. 4.
[๋ฐฑ์ค€] 1051๋ฒˆ: ์ˆซ์ž ์ •์‚ฌ๊ฐํ˜•(์™„์ „ ํƒ์ƒ‰, ๊ตฌํ˜„) https://www.acmicpc.net/problem/1051 1051๋ฒˆ: ์ˆซ์ž ์ •์‚ฌ๊ฐํ˜• N*Mํฌ๊ธฐ์˜ ์ง์‚ฌ๊ฐํ˜•์ด ์žˆ๋‹ค. ๊ฐ ์นธ์€ ํ•œ ์ž๋ฆฌ ์ˆซ์ž๊ฐ€ ์ ํ˜€ ์žˆ๋‹ค. ์ด ์ง์‚ฌ๊ฐํ˜•์—์„œ ๊ผญ์ง“์ ์— ์“ฐ์—ฌ ์žˆ๋Š” ์ˆ˜๊ฐ€ ๋ชจ๋‘ ๊ฐ™์€ ๊ฐ€์žฅ ํฐ ์ •์‚ฌ๊ฐํ˜•์„ ์ฐพ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ด๋•Œ, ์ •์‚ฌ๊ฐํ˜•์€ ํ–‰ ๋˜๋Š” ์—ด์— ํ‰ํ–‰ํ•ด์•ผ ํ•œ๋‹ค. 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[][] arr = new int[N][M]; i.. 2020. 3. 3.
[๋ฐฑ์ค€] 4948๋ฒˆ: ๋ฒ ๋ฅดํŠธ๋ž‘ ๊ณต์ค€(์†Œ์ˆ˜, ์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด) https://www.acmicpc.net/problem/4948 4948๋ฒˆ: ๋ฒ ๋ฅดํŠธ๋ž‘ ๊ณต์ค€ ๋ฌธ์ œ ๋ฒ ๋ฅดํŠธ๋ž‘ ๊ณต์ค€์€ ์ž„์˜์˜ ์ž์—ฐ์ˆ˜ n์— ๋Œ€ํ•˜์—ฌ, n๋ณด๋‹ค ํฌ๊ณ , 2n๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์†Œ์ˆ˜๋Š” ์ ์–ด๋„ ํ•˜๋‚˜ ์กด์žฌํ•œ๋‹ค๋Š” ๋‚ด์šฉ์„ ๋‹ด๊ณ  ์žˆ๋‹ค. ์ด ๋ช…์ œ๋Š” ์กฐ์ œํ”„ ๋ฒ ๋ฅดํŠธ๋ž‘์ด 1845๋…„์— ์ถ”์ธกํ–ˆ๊ณ , ํŒŒํ”„๋ˆ„ํ‹ฐ ์ฒด๋น„์‡ผํ”„๊ฐ€ 1850๋…„์— ์ฆ๋ช…ํ–ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, 10๋ณด๋‹ค ํฌ๊ณ , 20๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์†Œ์ˆ˜๋Š” 4๊ฐœ๊ฐ€ ์žˆ๋‹ค. (11, 13, 17, 19) ๋˜, 14๋ณด๋‹ค ํฌ๊ณ , 28๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์†Œ์ˆ˜๋Š” 3๊ฐœ๊ฐ€ ์žˆ๋‹ค. (17,19, 23) n์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, n๋ณด๋‹ค ํฌ๊ณ , 2n๋ณด www.acmicpc.net ์ฝ”๋“œ import java.util.Scanner; public class Main { // n ~ 2n๊นŒ์ง€ ์ˆ˜ ์ค‘ ์†Œ์ˆ˜์˜ ๊ฐฏ์ˆ˜ ๋ฆฌ.. 2020. 3. 3.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - ๋ฉ€๋ฆฌ ๋›ฐ๊ธฐ(DP) https://programmers.co.kr/learn/courses/30/lessons/12914 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ฉ€๋ฆฌ ๋›ฐ๊ธฐ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ํšจ์ง„์ด๋Š” ๋ฉ€๋ฆฌ ๋›ฐ๊ธฐ๋ฅผ ์—ฐ์Šตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํšจ์ง„์ด๋Š” ํ•œ๋ฒˆ์— 1์นธ, ๋˜๋Š” 2์นธ์„ ๋›ธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์นธ์ด ์ด 4๊ฐœ ์žˆ์„ ๋•Œ, ํšจ์ง„์ด๋Š” (1์นธ, 1์นธ, 1์นธ, 1์นธ) (1์นธ, 2์นธ, 1์นธ) (1์นธ, 1์นธ, 2์นธ) (2์นธ, 1์นธ, 1์นธ) (2์นธ, 2์นธ) ์˜ 5๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ๋งจ ๋ ์นธ์— ๋„๋‹ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฉ€๋ฆฌ๋›ฐ๊ธฐ์— ์‚ฌ์šฉ๋  ์นธ์˜ ์ˆ˜ n์ด ์ฃผ์–ด์งˆ ๋•Œ, ํšจ์ง„์ด๊ฐ€ ๋์— ๋„๋‹ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ๋ช‡ ๊ฐ€์ง€์ธ์ง€ ์•Œ์•„๋‚ด, ์—ฌ๊ธฐ์— 1234567๋ฅผ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solut programmers.co.kr ์ฝ”๋“œ class Solution { public long solution.. 2020. 3. 3.
๋ฐ˜์‘ํ˜•