From a9fdbbe3694e07f76e7441ee10f3d6dabee8f471 Mon Sep 17 00:00:00 2001 From: Jeongho Kim Date: Tue, 1 Jul 2025 10:27:16 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[=EA=B9=80=EC=A0=95=ED=98=B8]=EA=BD=89=20?= =?UTF-8?q?=EC=9E=90=EB=B0=94=20=EC=B2=AB=20=EC=A3=BC=20=EC=BD=94=ED=85=8C?= =?UTF-8?q?=20=ED=92=80=EC=9D=B4=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A4=20340211=EB=B2=88=20=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.name | 2 +- .idea/inspectionProfiles/Project_Default.xml | 6 ++ src/week01/Unoguna/PG_340211.java | 105 +++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 src/week01/Unoguna/PG_340211.java diff --git a/.idea/.name b/.idea/.name index 42061c0..ae84d7c 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -README.md \ No newline at end of file +PG_340211.java \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..51f4a11 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/src/week01/Unoguna/PG_340211.java b/src/week01/Unoguna/PG_340211.java new file mode 100644 index 0000000..bb5e02f --- /dev/null +++ b/src/week01/Unoguna/PG_340211.java @@ -0,0 +1,105 @@ +package week01.Unoguna; + +public class PG_340211 { + + public static void main(String[] args){ + int[][] points = new int[][]{{3, 2}, {6, 4}, {4, 7}, {1, 4}}; + int[][] routes = new int[][]{{4, 2}, {1, 3}, {2, 4}}; + + Solution s = new Solution(); + + System.out.println(s.solution(points, routes)); + } + + public static class Solution { + class Robot{ + int x; + int y; + + int location_x; + int location_y; + + int[] route; + int route_idx; + + boolean end; + + Robot(int[] route, int x, int y, int location_x, int location_y){ + route_idx = 1; + this.route = route; + this.x = x; + this.y = y; + this.location_x = location_x; + this.location_y = location_y; + this.end = false; + } + } + + public int solution(int[][] points, int[][] routes) { + int answer = 0; + int end_num = 0; + + int[][] matrix = new int[101][101]; + + Robot[] robot = new Robot[routes.length]; + + for(int i=0; i 1) answer++; + matrix[j][i] = 0; + } + } + + //다음 동작 + for(int i=0; i robot[i].location_y ? -1 : 1; + } + else{ + //가로 움직 + robot[i].x += robot[i].x > robot[i].location_x ? -1 : 1; + } + } + } + + return answer; + } + } +} From 0e048d42a3004af0b83207964b3bd5952a3a14a2 Mon Sep 17 00:00:00 2001 From: Jeongho Kim Date: Tue, 1 Jul 2025 12:50:33 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[=EA=B9=80=EC=A0=95=ED=98=B8]=EA=BD=89=20?= =?UTF-8?q?=EC=9E=90=EB=B0=94=20=EC=B2=AB=20=EC=A3=BC=20=EC=BD=94=ED=85=8C?= =?UTF-8?q?=20=ED=92=80=EC=9D=B4=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A4=20340211=EB=B2=88=20=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week01/Unoguna/PG_340211.java | 54 ++++++++++++++++++------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/week01/Unoguna/PG_340211.java b/src/week01/Unoguna/PG_340211.java index bb5e02f..780b1f2 100644 --- a/src/week01/Unoguna/PG_340211.java +++ b/src/week01/Unoguna/PG_340211.java @@ -13,19 +13,19 @@ public static void main(String[] args){ public static class Solution { class Robot{ - int x; - int y; + int x; //로봇의 현재 좌표x + int y; //로봇의 현재 좌표y - int location_x; - int location_y; + int location_x; //로봇의 현재 목적지의 좌표x + int location_y; //로봇의 현재 목적지의 좌표y - int[] route; - int route_idx; + int[] route; //로봇의 이동경로 + int route_idx; //현재 가야하는 route의 idx - boolean end; + boolean end; //최종 목적지에 도착하면 true 아니면 false Robot(int[] route, int x, int y, int location_x, int location_y){ - route_idx = 1; + route_idx = 1; //0은 시작지점이기 때문에 첫 목적지의 idx는 1 this.route = route; this.x = x; this.y = y; @@ -35,25 +35,29 @@ class Robot{ } } + //points는 특정 지점의 위치를 담고 있다. + //routes는 각 로봇들의 이동경로를 담고 있다. public int solution(int[][] points, int[][] routes) { int answer = 0; - int end_num = 0; + int end_num = 0; //최종 목적지까지 도착이 완료된 로봇의 개수 - int[][] matrix = new int[101][101]; + int[][] matrix = new int[101][101]; //해당 위치의 로봇의 개수를 표시하기위한 배열 생성 전체 가로, 세로의 최대 길이가 100이라 101로 할당 Robot[] robot = new Robot[routes.length]; + //로봇들을 생성 for(int i=0; i 1) answer++; - matrix[j][i] = 0; + if(matrix[j][i] > 1) answer++; //해당위치에 로봇의 개수가 2개이상일 경우 충돌이 발생 + matrix[j][i] = 0; //해당위치 확인후 초기화 시켜준다. } } - //다음 동작 + //로봇들을 다음 이동할 위치로 이동 for(int i=0; i robot[i].location_y ? -1 : 1; } else{ - //가로 움직 + //가로 이동 robot[i].x += robot[i].x > robot[i].location_x ? -1 : 1; } }