java 544

[Baekjoon] 1495_๊ธฐํƒ€๋ฆฌ์ŠคํŠธ

Silver I๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/1495) ๋ฌธ์ œ ํ’€์ด  ์ฒ˜์Œ์—๋Š” queue๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๋ณผ๋ฅจ์„ add์™€ pop์„ ํ†ตํ•ด ๊ตฌํ–ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ•  ๊ฒฝ์šฐ ๋ฉ”๋ชจ๋ฆฌ ์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•ด์„œ ์–ด๋–ป๊ฒŒ ๊ณ ์ณ์•ผ ํ• ์ง€ ๋ชฐ๋ž๋‹ค.  ์ฐพ์•„๋ณธ ๊ฒฐ๊ณผ 0 ์ด์ƒ M์ดํ•˜์˜ ๊ฐ’๋งŒ ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ ๋ฐฐ์—ด์„ m+1๋งŒํผ ์„ ์–ธํ•œ ํ›„์— ๋ฐฐ์—ด[๋ณผ๋ฅจ] = ์ธ๋ฑ์Šค๋กœ ๊ฐ’์„ ๊ตฌํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ ์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด1 5 105 ์ด๋ผ๋ฉด temp [5]=1๋กœ ์ดˆ๊ธฐํ™”ํ•œ ํ›„์— 0๋ฒˆ์งธ ๊ณก์„ ์—ฐ์ฃผํ•˜๊ธฐ ์œ„ํ•ด ๋ณผ๋ฅจ์„ ๋ฐ”๊พผ๋‹ค๊ณ  ํ•˜์ž.temp [10]=2, temp [0]=2๊ฐ€ ๋œ๋‹ค. 0 ์ด์ƒ M์ดํ•˜์ธ ๋ฐฐ์—ด์„ ์ „์ฒด ํƒ์ƒ‰ํ•˜์—ฌ ๋ฐฐ์—ด ๊ฐ’์ด 2์ธ ์ธ๋ฑ์Šค ์ค‘์— ์ตœ๋Œ“๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.  my solution (Java)import j..

[Baekjoon] 16194_์นด๋“œ ๊ตฌ๋งคํ•˜๊ธฐ 2

Silver I๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/16194) ๋ฌธ์ œ ํ’€์ด  ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•ด์„œ ์นด๋“œ๋ฅผ ๊ตฌ๋งคํ•  ๋•Œ์˜ ์ตœ์†Ÿ๊ฐ’์„ ๊ตฌํ•œ๋‹ค. ๋ฐฑ์ค€ 11052๋ฒˆ ์นด๋“œ ๊ตฌ๋งคํ•˜๊ธฐ ๋ฌธ์ œ์—์„œ ์ตœ๋Œ“๊ฐ’์„ ์ตœ์†Ÿ๊ฐ’์œผ๋กœ ๋ฐ”๊พธ๋ฉด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค. https://melody-coding.tistory.com/453 [Baekjoon] 11052_์นด๋“œ ๊ตฌ๋งคํ•˜๊ธฐSilver I๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/11052) ๋ฌธ์ œ ํ’€์ด  ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•ด์„œ ์นด๋“œ๋ฅผ ๊ตฌ๋งคํ•  ๋•Œ์˜ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•œ๋‹ค.  my solution (Java)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreme..

[Baekjoon] 11052_์นด๋“œ ๊ตฌ๋งคํ•˜๊ธฐ

Silver I๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/11052) ๋ฌธ์ œ ํ’€์ด  ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•ด์„œ ์นด๋“œ๋ฅผ ๊ตฌ๋งคํ•  ๋•Œ์˜ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•œ๋‹ค.  my solution (Java)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class _11052_ { // ์นด๋“œ ๊ตฌ๋งคํ•˜๊ธฐ public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in..

[Baekjoon] 27497_์•ŒํŒŒ๋ฒณ ๋ธ”๋ก

Silver II๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/27497) ๋ฌธ์ œ ํ’€์ด  deque์™€ stack์„ ์‚ฌ์šฉํ•ด์„œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ๋‹ค. deque์—๋Š” ๋ฌธ์ž์—ด์„ ๋„ฃ๊ณ , stack์—๋Š” ๋ฌธ์ž์—ด์„ ์•ž์— ๋„ฃ์—ˆ๋Š”์ง€ ๋’ค์— ๋„ฃ์—ˆ๋Š”์ง€ ํŒ๋ณ„ํ•˜๋„๋ก ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค.  my solution (Java)import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.util.ArrayDeque;import java.util.Deque;import java.util.Stac..

[Baekjoon] 2872_์šฐ๋ฆฌ์ง‘์—” ๋„์„œ๊ด€์ด ์žˆ์–ด

Silver II๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/2872) ๋ฌธ์ œ ํ’€์ด  ์‚ฌ์ „ ์ˆœ์œผ๋กœ ๋†“๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ œ์ผ ํฐ ๊ฐ’์ด ๋ฐ‘์— ์žˆ๋Š”์ง€๋ถ€ํ„ฐ ํ™•์ธํ•œ๋‹ค. ๋งŒ์•ฝ 1 3 4 2 ์ˆœ์œผ๋กœ ๋˜์–ด์žˆ๋‹ค๋ฉด 3 4๋Š” ์ˆœ์„œ๋Œ€๋กœ ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ 1 2๋งŒ ๋‹ค์‹œ ์Œ“์œผ๋ฉด ๋œ๋‹ค.  my solution (Java)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class _2872_ { // ์šฐ๋ฆฌ์ง‘์—” ๋„์„œ๊ด€์ด ์žˆ์–ด public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedRead..

[Baekjoon] 5212_์ง€๊ตฌ ์˜จ๋‚œํ™”

Silver II๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/5212) ๋ฌธ์ œ ํ’€์ด  ์ธ์ ‘ํ•œ ์„ธ ์นธ ๋˜๋Š” ๋„ค ์นธ์— ๋ฐ”๋‹ค๊ฐ€ ์žˆ๋Š” ๋•…์„ ๋ฐ”๋‹ค๋กœ ๋ฐ”๊พผ ํ›„ ์„ฌ์ด ์žˆ๋Š” ๊ณณ์˜ ๊ฐ€์žฅ ์ž‘์€ ์ขŒํ‘œ์™€ ๊ฐ€์žฅ ํฐ ์ขŒํ‘œ๋ฅผ ๊ตฌํ•ด ๊ตฌ๊ฐ„๋งŒํผ ์ถœ๋ ฅํ•œ๋‹ค.  my solution (Java)import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.util.StringTokenizer;public class _5212_ { // ์ง€๊ตฌ ์˜จ๋‚œํ™” static char[][] arr, r..

[Baekjoon] 18429_๊ทผ์†์‹ค

Silver III๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/18429) ๋ฌธ์ œ ํ’€์ด  ์กฐํ•ฉ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ํ™•์ธํ•œ๋‹ค. ํ™•์ธํ•˜๋ฉด์„œ 500 ๋ฏธ๋งŒ์ด ๋˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ ์กฐํ•ฉ์„ ํ™•์ธํ•œ๋‹ค.  my solution (Java)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class _18429_ { // ๊ทผ์†์‹ค static int arr[], answer; static boolean visited[]; public static void main(String[] args) throws IOExcep..

[Baekjoon] 1448_์‚ผ๊ฐํ˜• ๋งŒ๋“ค๊ธฐ

Silver III๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/1448) ๋ฌธ์ œ ํ’€์ด  ์‚ผ๊ฐํ˜•์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์กฐ๊ฑด์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.๐ŸŒฑ ์‚ผ๊ฐํ˜• ๋งŒ๋“œ๋Š” ์กฐ๊ฑด๊ฐ€์žฅ ๊ธด ๋ณ€์˜ ๊ธธ์ด   my solution (Java)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Arrays;import java.util.Collections;public class _1448_ { // ์‚ผ๊ฐํ˜• ๋งŒ๋“ค๊ธฐ public static void main(String[] args) throws IOException { BufferedReader bf = new Buffere..

[Baekjoon] 6550_๋ถ€๋ถ„ ๋ฌธ์ž์—ด

Silver V๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/6550) ๋ฌธ์ œ ํ’€์ด  s๊ฐ€ t์˜ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์ธ์ง€ ํ™•์ธํ•œ๋‹ค.   my solution (Java)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class _6550_ { // ๋ถ€๋ถ„ ๋ฌธ์ž์—ด public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String..

[Baekjoon] 3135_๋ผ๋””์˜ค

Silver V๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/3135) ๋ฌธ์ œ ํ’€์ด  ํ˜„์žฌ ์ฃผํŒŒ์ˆ˜์—์„œ ๋“ฃ๊ณ  ์‹ถ์€ ์ฃผํŒŒ์ˆ˜๋กœ ๊ฐ€๊ธฐ ์œ„ํ•ด ๋ฏธ๋ฆฌ ์ง€์ •๋˜์–ด ์žˆ๋Š” ์ฃผํŒŒ์ˆ˜๋กœ ์ด๋™ํ•˜๋Š” ๊ฒƒ์ด ๋ฒ„ํŠผ์„ ์ ๊ฒŒ ๋ˆ„๋ฅด๋Š”์ง€ ํŒ๋‹จ ํ›„ ์ ๊ฒŒ ๋ˆ„๋ฅด๋ฉด ์ด๋™ํ•˜๊ณ  ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์ด๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค.   my solution (Java)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.PriorityQueue;import java.util.StringTokenizer;public class _3135_ { // ๋ผ๋””์˜ค public static void main(String[] args)..