From 7e2d4261eba6d26afc9c9d10cf16a10bdc1b2c98 Mon Sep 17 00:00:00 2001 From: ygs Date: Mon, 24 Mar 2025 02:01:38 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[40=EC=A3=BC=EC=B0=A8=20/=20=EC=9C=A4?= =?UTF-8?q?=EA=B1=B4=EC=88=98]=20Test=20Main?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestMain.java" | 44 ++++++++++++++++--- .../baekjoon/G4_22856/Main.java" | 4 ++ .../baekjoon/G4_22856/input1.txt" | 8 ++++ .../baekjoon/G4_22856/input2.txt" | 2 + .../baekjoon/G4_22856/result1.txt" | 1 + .../baekjoon/G4_22856/result2.txt" | 1 + .../baekjoon/S2_11055/Main.java" | 4 ++ .../baekjoon/S2_11055/input1.txt" | 2 + .../baekjoon/S2_11055/result1.txt" | 1 + .../programmers/LV2_169198/Solution.java" | 4 ++ .../programmers/LV2_169198/TestCase.java" | 19 ++++++++ 11 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/Main.java" create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input1.txt" create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input2.txt" create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result1.txt" create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result2.txt" create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/Main.java" create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/input1.txt" create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/result1.txt" create mode 100644 "\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/Solution.java" create mode 100644 "\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/TestCase.java" diff --git "a/\354\234\244\352\261\264\354\210\230/TestMain.java" "b/\354\234\244\352\261\264\354\210\230/TestMain.java" index c756b09..f1b1d0c 100644 --- "a/\354\234\244\352\261\264\354\210\230/TestMain.java" +++ "b/\354\234\244\352\261\264\354\210\230/TestMain.java" @@ -8,21 +8,55 @@ public static void main(String[] args) throws Exception { Programmers programmers = new Programmers(); Leetcode leetcode = new Leetcode(); + /* + * 스터디 40주차 + * */ + + // 당구 연습 (Level 2) + // https://school.programmers.co.kr/learn/courses/30/lessons/169198 + programmers.setAnswer(new programmers.LV2_169198.Solution()).test(); + + // 트리 순회 (Gold 4) + // https://www.acmicpc.net/problem/22856 + baekJoon.setAnswer(new baekjoon.G4_22856.Main()).test(); + + // 가장 큰 증가하는 부분 수열 (Silver 2) + // https://www.acmicpc.net/problem/11055 + baekJoon.setAnswer(new baekjoon.S2_11055.Main()).test(); + + + /* + * 스터디 39주차 + * */ + + // 전구 (Gold 2) + // https://www.acmicpc.net/problem/2550 + // baekJoon.setAnswer(new baekjoon.G2_2550.Main()).test(); + + // 야근 지수 (Level 3) + // https://school.programmers.co.kr/learn/courses/30/lessons/12927 + // programmers.setAnswer(new programmers.LV3_12927.Solution()).test(); + + // 가장 긴 증가하는 부분 수열 2 (Gold 2) + // https://www.acmicpc.net/problem/12015 + // baekJoon.setAnswer(new baekjoon.G2_12015.Main()).test(); + + /* * 스터디 38주차 * */ // 말이 되고픈 원숭이 (Gold 3) // https://www.acmicpc.net/problem/1600 - baekJoon.setAnswer(new baekjoon.G3_1600.Main()).test(); + // baekJoon.setAnswer(new baekjoon.G3_1600.Main()).test(); // 앱 (Gold 3) // https://www.acmicpc.net/problem/7579 - baekJoon.setAnswer(new baekjoon.G3_7579.Main()).test(); + // baekJoon.setAnswer(new baekjoon.G3_7579.Main()).test(); // 배달 (Level 2) // https://school.programmers.co.kr/learn/courses/30/lessons/12978 - programmers.setAnswer(new programmers.LV2_12987.Solution()).test(); + // programmers.setAnswer(new programmers.LV2_12987.Solution()).test(); /* @@ -125,8 +159,8 @@ public static void main(String[] args) throws Exception { // 멀티탭 스케쥴링 (Gold 1) // https://www.acmicpc.net/problem/1700 // baekJoon.setAnswer(new baekjoon.G1_1700.Main()).test(); - - + + /* * 스터디 31주차 * */ diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/Main.java" "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/Main.java" new file mode 100644 index 0000000..5d78760 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/Main.java" @@ -0,0 +1,4 @@ +package baekjoon.G4_22856; + +public class Main { +} diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input1.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input1.txt" new file mode 100644 index 0000000..3bea399 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input1.txt" @@ -0,0 +1,8 @@ +7 +1 2 3 +2 4 5 +3 6 7 +4 -1 -1 +5 -1 -1 +6 -1 -1 +7 -1 -1 \ No newline at end of file diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input2.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input2.txt" new file mode 100644 index 0000000..a170987 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input2.txt" @@ -0,0 +1,2 @@ +1 +1 -1 -1 \ No newline at end of file diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result1.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result1.txt" new file mode 100644 index 0000000..9a03714 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result1.txt" @@ -0,0 +1 @@ +10 \ No newline at end of file diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result2.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result2.txt" new file mode 100644 index 0000000..c227083 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result2.txt" @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/Main.java" "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/Main.java" new file mode 100644 index 0000000..57cb826 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/Main.java" @@ -0,0 +1,4 @@ +package baekjoon.S2_11055; + +public class Main { +} diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/input1.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/input1.txt" new file mode 100644 index 0000000..8d16944 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/input1.txt" @@ -0,0 +1,2 @@ +10 +1 100 2 50 60 3 5 6 7 8 \ No newline at end of file diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/result1.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/result1.txt" new file mode 100644 index 0000000..95c8a67 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/result1.txt" @@ -0,0 +1 @@ +113 \ No newline at end of file diff --git "a/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/Solution.java" "b/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/Solution.java" new file mode 100644 index 0000000..b804627 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/Solution.java" @@ -0,0 +1,4 @@ +package programmers.LV2_169198; + +public class Solution { +} diff --git "a/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/TestCase.java" "b/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/TestCase.java" new file mode 100644 index 0000000..91e33a6 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/TestCase.java" @@ -0,0 +1,19 @@ +package programmers.LV2_169198; + +import java.util.HashMap; + +public class TestCase { + + public HashMap getInput() { + HashMap testCase = new HashMap<>(); + testCase.put("case1", new Object[]{10, 10, 3, 7, new int[][]{{7, 7}, {2, 7}, {7, 3}}}); + return testCase; + } + + public HashMap getResult() { + HashMap resultCase = new HashMap<>(); + resultCase.put("case1", new int[]{52, 37, 116}); + return resultCase; + } + +} From a0d813c23bf6c87b66793ab6c6b31bd004006490 Mon Sep 17 00:00:00 2001 From: ygs Date: Wed, 26 Mar 2025 00:59:27 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[40=EC=A3=BC=EC=B0=A8=20/=20=EC=9C=A4?= =?UTF-8?q?=EA=B1=B4=EC=88=98]=20=EA=B0=80=EC=9E=A5=20=ED=81=B0=20?= =?UTF-8?q?=EC=A6=9D=EA=B0=80=ED=95=98=EB=8A=94=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=97=B4=20(Silver=202)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baekjoon/S2_11055/Main.java" | 31 +++++++++++++++++++ .../baekjoon/S2_11055/input2.txt" | 2 ++ .../baekjoon/S2_11055/result2.txt" | 1 + 3 files changed, 34 insertions(+) create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/input2.txt" create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/result2.txt" diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/Main.java" "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/Main.java" index 57cb826..91d53b7 100644 --- "a/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/Main.java" +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/Main.java" @@ -1,4 +1,35 @@ package baekjoon.S2_11055; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + public class Main { + + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int cnt = Integer.parseInt(br.readLine()); + int[] arr = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); + int[] dp = new int[cnt]; + + for(int i = 0; i < cnt; i++){ + int num1 = arr[i]; + int beforeSeqIdx = -1; + int result = num1; + for(int j = i - 1; j >= 0; j--){ + int num2 = arr[j]; + if(num2 < num1) { + result = Math.max(result, dp[j] + num1); + } + } + + dp[i] = result; + } + + System.out.println(Arrays.stream(dp).max().getAsInt()); + + } + } diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/input2.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/input2.txt" new file mode 100644 index 0000000..34e3aa3 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/input2.txt" @@ -0,0 +1,2 @@ +5 +3 2 2 4 5 \ No newline at end of file diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/result2.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/result2.txt" new file mode 100644 index 0000000..3cacc0b --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/S2_11055/result2.txt" @@ -0,0 +1 @@ +12 \ No newline at end of file From eb3f04e7fcaa357eb0ad6edd7d9fd646dde94336 Mon Sep 17 00:00:00 2001 From: ygs Date: Wed, 26 Mar 2025 23:36:53 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[40=EC=A3=BC=EC=B0=A8=20/=20=EC=9C=A4?= =?UTF-8?q?=EA=B1=B4=EC=88=98]=20=ED=8A=B8=EB=A6=AC=20=EC=88=9C=ED=9A=8C?= =?UTF-8?q?=20(Gold=204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baekjoon/G4_22856/Main.java" | 86 +++++++++++++++++++ .../baekjoon/G4_22856/input3.txt" | 10 +++ .../baekjoon/G4_22856/result3.txt" | 1 + 3 files changed, 97 insertions(+) create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input3.txt" create mode 100644 "\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result3.txt" diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/Main.java" "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/Main.java" index 5d78760..d099d2b 100644 --- "a/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/Main.java" +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/Main.java" @@ -1,4 +1,90 @@ package baekjoon.G4_22856; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + public class Main { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int nodeCnt = Integer.parseInt(br.readLine()); + Node[] nodes = new Node[nodeCnt + 1]; + for (int i = 1; i < nodeCnt + 1; i++) { + nodes[i] = new Node(); + nodes[i].num = i; + } + + + Node emptyNode = new Node(); + emptyNode.isVisited = true; + String line = ""; + while ((line = br.readLine()) != null) { + int[] info = Arrays.stream(line.split(" ")).mapToInt(Integer::parseInt).toArray(); + int nodeNum = info[0]; + int leftNodeNum = info[1]; + int rightNodeNum = info[2]; + Node parentNode = nodes[nodeNum]; + + if(leftNodeNum != -1){ + Node leftNode = nodes[leftNodeNum]; + parentNode.left = leftNode; + leftNode.parent = parentNode; + }else{ + parentNode.left = emptyNode; + } + + if(rightNodeNum != -1){ + Node rightNode = nodes[rightNodeNum]; + parentNode.right = rightNode; + rightNode.parent = parentNode; + }else { + parentNode.right = emptyNode; + } + } + + int root = 1; + int moveCnt = 0; + Node currentNode = nodes[root]; + if(currentNode.left.isVisited && currentNode.right.isVisited){ + System.out.println(0); + return; + } + + Set visitedNum = new HashSet<>(); + while (true) { + if (currentNode.left.isVisited) { + currentNode.isVisited = true; + visitedNum.add(currentNode.num); + + if(visitedNum.size() == nodeCnt) break; + } + + if(!currentNode.left.isVisited){ + currentNode = currentNode.left; + }else if(!currentNode.right.isVisited){ + currentNode = currentNode.right; + }else { + if(currentNode.parent != null) { + currentNode = currentNode.parent; + } + + } + moveCnt++; + } + + System.out.println(moveCnt); + } + + private static class Node{ + int num; + Node parent; + Node left; + Node right; + boolean isVisited = false; + } + } diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input3.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input3.txt" new file mode 100644 index 0000000..d523d5d --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/input3.txt" @@ -0,0 +1,10 @@ +9 +1 2 4 +2 3 -1 +3 -1 -1 +4 5 6 +5 -1 -1 +6 -1 7 +7 8 -1 +8 -1 9 +9 -1 -1 \ No newline at end of file diff --git "a/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result3.txt" "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result3.txt" new file mode 100644 index 0000000..ca7bf83 --- /dev/null +++ "b/\354\234\244\352\261\264\354\210\230/baekjoon/G4_22856/result3.txt" @@ -0,0 +1 @@ +13 \ No newline at end of file From 4442ffaa23c7d132b2765eaece02f44ceff67514 Mon Sep 17 00:00:00 2001 From: ygs Date: Sun, 30 Mar 2025 15:20:51 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[40=EC=A3=BC=EC=B0=A8=20/=20=EC=9C=A4?= =?UTF-8?q?=EA=B1=B4=EC=88=98]=20=EB=8B=B9=EA=B5=AC=20=EC=97=B0=EC=8A=B5?= =?UTF-8?q?=20(Level=202)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../programmers/LV2_169198/Solution.java" | 73 ++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git "a/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/Solution.java" "b/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/Solution.java" index b804627..1e94a3a 100644 --- "a/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/Solution.java" +++ "b/\354\234\244\352\261\264\354\210\230/programmers/LV2_169198/Solution.java" @@ -1,4 +1,75 @@ package programmers.LV2_169198; public class Solution { -} + public int[] solution(int m, int n, int startX, int startY, int[][] balls) { + Point start = new Point(startX, startY); + int[] answer = new int[balls.length]; + for(int i = 0; i < balls.length; i++){ + Point ball = new Point(balls[i][0], balls[i][1]); + int minDist = Integer.MAX_VALUE; + + for(int j = 4; j < 8; j++){ + Point point = convertPoint(ball, j, m, n); + if(isValid(j, start, point, ball, m, n)){ + int dist = start.calcDist(point); + minDist = Math.min(dist, minDist); + }; + } + + answer[i] = minDist; + } + + return answer; + } + + private boolean isValid(int direction, Point point1, Point point2, Point ball, int m, int n){ + boolean isBetweenX = ball.y == point1.y + && (ball.x < Math.max(point1.x, point2.x)) + && (ball.x > Math.min(point1.x, point2.x)); + boolean isBetweenY = ball.x == point1.x + && (ball.y < Math.max(point1.y, point2.y)) + && (ball.y > Math.min(point1.y, point2.y)); + return !isBetweenX && !isBetweenY; + + } + + private Point convertPoint(Point point, int line, int m, int n){ + int x = 0; + int y = 0; + + switch(line){ + case 4: // 좌 + x = 0 - point.x; + y = point.y; + break; + case 5: // 위 + x = point.x; + y = n + (n - point.y); + break; + case 6: // 우 + x = m + (m - point.x); + y = point.y; + break; + case 7: // 하 + x = point.x; + y = 0 - point.y; + break; + } + + return new Point(x, y); + } + + public static class Point{ + int x; + int y; + + Point(int x, int y){ + this.x = x; + this.y = y; + } + + public int calcDist(Point o){ + return (int)Math.pow((this.x - o.x), 2) + (int)Math.pow((this.y - o.y), 2); + } + } +} \ No newline at end of file