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..780b1f2 --- /dev/null +++ b/src/week01/Unoguna/PG_340211.java @@ -0,0 +1,113 @@ +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; //로봇의 현재 좌표x + int y; //로봇의 현재 좌표y + + int location_x; //로봇의 현재 목적지의 좌표x + int location_y; //로봇의 현재 목적지의 좌표y + + int[] route; //로봇의 이동경로 + int route_idx; //현재 가야하는 route의 idx + + boolean end; //최종 목적지에 도착하면 true 아니면 false + + Robot(int[] route, int x, int y, int location_x, int location_y){ + route_idx = 1; //0은 시작지점이기 때문에 첫 목적지의 idx는 1 + this.route = route; + this.x = x; + this.y = y; + this.location_x = location_x; + this.location_y = location_y; + this.end = false; + } + } + + //points는 특정 지점의 위치를 담고 있다. + //routes는 각 로봇들의 이동경로를 담고 있다. + public int solution(int[][] points, int[][] routes) { + int answer = 0; + int end_num = 0; //최종 목적지까지 도착이 완료된 로봇의 개수 + + int[][] matrix = new int[101][101]; //해당 위치의 로봇의 개수를 표시하기위한 배열 생성 전체 가로, 세로의 최대 길이가 100이라 101로 할당 + + Robot[] robot = new Robot[routes.length]; + + //로봇들을 생성 + for(int i=0; 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; + } + } + } + + return answer; + } + } +}