From 4bee63bbea649e970b5587b6b26626d5d18d6dec Mon Sep 17 00:00:00 2001 From: monsileI Date: Thu, 2 Jun 2022 19:49:10 +0900 Subject: [PATCH] =?UTF-8?q?dijkstra=20=EC=99=A4=EC=BC=80=20=EC=96=B4?= =?UTF-8?q?=EB=A0=A4=EC=9B=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today_22_06_02/arrow.java | 91 ++++++++++++++++++ .../src/Today_22_06_02/coronaTest.java | 90 ++++++++++++++++++ .../src/Today_22_06_02/delivery.java | 80 ++++++++++++++++ .../src/Today_22_06_02/hanoi.java | 34 +++++++ .../src/Today_22_06_02/openChatting.java | 57 ++++++++++++ .../src/Today_22_06_02/test.java | 92 +++++++++++++++++++ 6 files changed, 444 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_06_02/arrow.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_02/coronaTest.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_02/delivery.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_02/hanoi.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_02/openChatting.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_02/test.java diff --git a/Basic_Of_Algorithm/src/Today_22_06_02/arrow.java b/Basic_Of_Algorithm/src/Today_22_06_02/arrow.java new file mode 100644 index 0000000..8206112 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_02/arrow.java @@ -0,0 +1,91 @@ +package Today_22_06_02; + +import java.util.ArrayList; +import java.util.Collections; + +public class arrow { + + static int apeach[]; + static int ryan[]; + static int count; + static int maxvalue = 0; + static ArrayList answerList = new ArrayList<>(); + + public static void main(String[] args) { + + int[]info = {0,0,1,2,0,1,1,1,1,1,1}; + int n = 9; + + apeach = info.clone(); + count = n; + ryan = new int[info.length]; + + dfs(0,0); + + int [] answer; + + if(answerList.isEmpty()) answer = new int[] {-1}; + + else { + + Collections.sort(answerList,(o1,o2)->{ + + for(int i=10;i>-1;i--) { + if(o1[i]!=o2[i]) return o2[i] - o1[i]; + } + + return 0; + + }); + + answer = new int[apeach.length]; + + for(int i=0;iapeach[i]) r += 10 - i; + else a += 10 - i; + } + + if(r>a) { + int diff = r - a; + if(diff>maxvalue) { + maxvalue = diff; + answerList.clear(); + answerList.add(ryan.clone()); + + }else if(diff==maxvalue) { + answerList.add(ryan.clone()); + } + } + + return; + } + + + for(int i=0;i<11;i++) { + ryan[i]++; + dfs(i,arrow+1); + ryan[i]--; + } + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_06_02/coronaTest.java b/Basic_Of_Algorithm/src/Today_22_06_02/coronaTest.java new file mode 100644 index 0000000..77a4024 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_02/coronaTest.java @@ -0,0 +1,90 @@ +package Today_22_06_02; + +public class coronaTest { + + public static void main(String[] args) { + + String[][]places = {{"POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"}, {"POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"}, {"PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"}, {"OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"}, {"PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"}}; + int []result = new int[places.length]; + + for(int i=0;i w) { + map[a][b] = w; + map[b][a] = w; + } + + } + + int [] dist = new int[n+1]; + for(int i = 2; i <= n ; i++) { + dist[i] = INF; + } + + boolean[] visited = new boolean[n+1]; + visited[1] = true; + + + for(int i=1; i <=n-1 ; i++) { + + int min_idx = 1; + int min_value = INF; + for(int j=2;j<=n;j++) { + if(!visited[j] && dist[j]dist[min_idx] + map[min_idx][j]) { + dist[j] = dist[min_idx] + map[min_idx][j]; + } + } + + } + + for(int i=1;i<=n;i++) { + if(dist[i]<=k) answer++; + } + + for(int i : dist)System.out.print(i+","); + System.out.println(); + System.out.println(answer); + } + +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/Today_22_06_02/hanoi.java b/Basic_Of_Algorithm/src/Today_22_06_02/hanoi.java new file mode 100644 index 0000000..408945d --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_02/hanoi.java @@ -0,0 +1,34 @@ +package Today_22_06_02; + +public class hanoi { + + public static void main(String[] args) { + + int n = 4; + + int [] arr = {1,2,3}; + + hanoi(arr[0],arr[1],arr[2],n); + + + //n개를 옮기는 문제는 n-1로 세분화되고 다시 n-1를 위해 1를 옮기는걸 세분화 시킨다 + // a -> b (n-1)개 옮기기 + // b - > c (n-1)개 옮기기 + //n ==1 마지막에 남은거 옮기기 + + } + + static void hanoi(int from, int by, int to,int n) { + + if(n==1) { + System.out.println(from + " - > " + to); + return; + } + + hanoi(from, to, by, n-1); + System.out.println(from + " - > " + to); + hanoi(by,from,to,n-1); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_06_02/openChatting.java b/Basic_Of_Algorithm/src/Today_22_06_02/openChatting.java new file mode 100644 index 0000000..f46536f --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_02/openChatting.java @@ -0,0 +1,57 @@ +package Today_22_06_02; + +import java.util.ArrayList; +import java.util.HashMap; + +public class openChatting { + + + + public static void main(String[] args) { + + String [] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"}; + ArrayList answerList = new ArrayList<>(); + + HashMapidMap = new HashMap<>(); + + for(String str : record) { + + String []temp = str.split(" "); + + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Leave")) continue; + + String nick = temp[2]; + + idMap.put(id, nick); + + + } + + for(String str : record) { + + String []temp = str.split(" "); + + String action = temp[0]; + if(action.equals("Change")) continue; + String id = temp[1]; + String nick = idMap.get(id); + + String ans = nick+"님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + } + + String[]answer = new String[answerList.size()]; + + for(int i=0;ivalue) { + map[start][end] = value; + map[end][start] = value; + } + + } + + + int[]dist = new int[n+1]; + + boolean[]visited = new boolean[n+1]; + + visited[1] = true; + + for(int i = 2 ;i<=n;i++) { + dist[i] = (dist[i]==0) ? INF : map[1][i]; + } + + for(int i : dist) System.out.print(i+","); + + System.out.println(); + + for(int i=1;i dist[min_idx] + map[min_idx][j]) { + dist[j] = dist[min_idx] + map[min_idx][j]; + } + + } + + + + } + + for(int i=1;i<=n;i++) { + if(dist[i]<=k)answer++; + } + + + System.out.println(answer); + + for(int i : dist)System.out.print(i+","); + System.out.println(); + for(boolean a : visited)System.out.print(a+","); + System.out.println(); + + } + + +}