From c418565dd03e898872112d7e8846e62841e47116 Mon Sep 17 00:00:00 2001 From: MonsileI <95079046+MonsileI@users.noreply.github.com> Date: Tue, 10 May 2022 22:44:23 +0900 Subject: [PATCH 01/48] Initial commit --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8376b04 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Basic_Of_Algorithm +알고리즘 기초 예제 및 테스트 From 91c0b5e41b39cc75b2e8f69ce9b149f88f9dbb6c Mon Sep 17 00:00:00 2001 From: monsileI Date: Thu, 12 May 2022 21:11:43 +0900 Subject: [PATCH 02/48] =?UTF-8?q?=EB=8B=A4=EA=B0=80=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EC=BD=94=ED=85=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today_22_05_12/RankingSearch.java | 86 +++++++++++++++++++ .../src/Today_22_05_12/apchuck.java | 57 ++++++++++++ .../src/Today_22_05_12/changebracket.java | 68 +++++++++++++++ .../src/Today_22_05_12/gameMap.java | 52 +++++++++++ .../src/Today_22_05_12/hide.java | 57 ++++++++++++ .../src/Today_22_05_12/hideAndFind.java | 66 ++++++++++++++ .../src/Today_22_05_12/rightbiggersoo.java | 41 +++++++++ .../src/Today_22_05_12/rooms.java | 46 ++++++++++ 8 files changed, 473 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_12/RankingSearch.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_12/apchuck.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_12/changebracket.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_12/gameMap.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_12/hide.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_12/hideAndFind.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_12/rooms.java diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/RankingSearch.java b/Basic_Of_Algorithm/src/Today_22_05_12/RankingSearch.java new file mode 100644 index 0000000..df087e1 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/RankingSearch.java @@ -0,0 +1,86 @@ +package Today_22_05_12; + +import java.util.HashMap; +import java.util.ArrayList; +import java.util.Collections; + +public class RankingSearch { + + static HashMap> map = new HashMap<>(); + + + public static void main(String[] args) { + + + String [] info = {"java backend junior pizza 150","python frontend senior chicken 210","python frontend senior chicken 150","cpp backend senior pizza 260","java backend junior chicken 80","python backend senior chicken 50"}; + + String [] query = {"java and backend and junior and pizza 100","python and frontend and senior and chicken 200","cpp and - and senior and pizza 250","- and backend and senior and - 150","- and - and - and chicken 100","- and - and - and - 150"}; + + int[]result = new int[query.length]; + + + for(int i=0;i list = map.get(key); + + int start = 0; + + int end = list.size()-1; + + + while(start<=end) { + + int mid = (start+end)/2; + + if(score<=list.get(mid)) end = mid-1; + else if(score>list.get(mid)) start = mid+1; + + + } + + return list.size()-start; + + + } + + static void dfs(String[]temp,int count,String now) { + + + if(count==4) { + if(!map.containsKey(now)) { + map.put(now, new ArrayList<>()); + } + map.get(now).add(Integer.parseInt(temp[4])); + return; + } + + dfs(temp,count+1,now+"-"); + dfs(temp,count+1,now+temp[count]); + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/apchuck.java b/Basic_Of_Algorithm/src/Today_22_05_12/apchuck.java new file mode 100644 index 0000000..7e9a852 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/apchuck.java @@ -0,0 +1,57 @@ +package Today_22_05_12; + +public class apchuck { + + public static void main(String[] args) { + + String s = "ababcdcdababcdcd"; + + + int answer = Integer.MAX_VALUE; + + + for(int i=1;i<=s.length()/2;i++) { + + + String result = ""; + String now = ""; String next = ""; + int count = 1; + + for(int j=0;j<=s.length()/i;j++) { + + + int start = j*i; + + int end = s.length() > i * (j+1) ? i * (j+1) : s.length(); + + now = next; + + next = s.substring(start,end); + + if(now.equals(next)) { + count++; + }else { + result += check(count) + now; + count = 1; + } + + + + } + + result += check(count) + next; + + System.out.println(result + " -> 갯수 : "+ result.length()); + + answer = Math.min(answer, result.length()); + + } + System.out.println(); + System.out.println("답 : " + answer); + + } + + static String check(int count) { + return count > 1 ? String.valueOf(count) : ""; + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/changebracket.java b/Basic_Of_Algorithm/src/Today_22_05_12/changebracket.java new file mode 100644 index 0000000..ba24c08 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/changebracket.java @@ -0,0 +1,68 @@ +package Today_22_05_12; + +public class changebracket { + + + public static void main(String[] args) { + + String p = ")("; + + if(p.isEmpty())System.out.println("nope"); + else { + + String answer = change(p); + System.out.println(answer); + } + + + + } + + static String change(String w) { + + if(w.isEmpty()) return ""; + + String u = ""; + String v = ""; + + int l = 0; + int r = 0; + int i; + + for(i=0;i q = new LinkedList<>(); + + + int[][]temp = new int[maps.length][maps[0].length]; + + int [][] move = {{0,1},{1,0},{0,-1},{-1,0}}; + + + temp[0][0] = 1; + + q.add(new int[] {0,0}); + + while(!q.isEmpty()) { + + int[]cur = q.poll(); + + int i = cur[0]; + int j = cur[1]; + + for(int d=0;d<4;d++) { + + int ni = i + move[d][0]; + int nj = j + move[d][1]; + + if(ni<0||nj<0||maps.length-1 q = new LinkedList<>(); + + int[] position = new int[100001]; + + + position[sb] = 0; + + q.add(sb); + + while(!q.isEmpty()) { + + + int p = q.poll(); + + if(position[bro]!=0) break; + + if(position[p-1] ==0 && p-1>=0) { + position[p-1] = position[p] + 1; + q.add(p-1); + } + + if(position[p+1] ==0 && p+1<=position.length) { + position[p+1] = position[p] + 1; + q.add(p+1); + + } + if(position[p*2] ==0 && p*2<=position.length) { + position[p*2] = position[p] + 1; + q.add(p*2); + + } + + + } + + if(sb==bro) position[bro] = 0; + System.out.println(position[bro] + " 초"); + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/hideAndFind.java b/Basic_Of_Algorithm/src/Today_22_05_12/hideAndFind.java new file mode 100644 index 0000000..a8bbb4e --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/hideAndFind.java @@ -0,0 +1,66 @@ +package Today_22_05_12; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.PriorityQueue; + +public class hideAndFind { + + public static void main(String[] args) { + + int[][]jobs = {{0, 3}, {1, 9}, {2, 6}}; + + int answer = 0; + + Arrays.sort(jobs, new Comparator() { + + @Override + public int compare(int[] o1, int[] o2) { + if(o1[0]==o2[0]) { + return o1[1] - o2[1]; + } + return o1[0] - o2[0]; + } + + }); + + + for(int i=0;i q = new PriorityQueue(new Comparator() { + + @Override + public int compare(int[] o1, int[] o2) { + // TODO Auto-generated method stub + return o1[1]-o2[1]; + } + + }); + + q.offer(jobs[0]); + int end = jobs[0][0]; + int sum = 0; + int idx = 1; + + while(!q.isEmpty()) { + int [] cur = q.poll(); + end += cur[1]; + sum += end - cur[0]; + System.out.println(sum); + + while(idx < jobs.length && jobs[idx][0] <= end) { + q.offer(jobs[idx++]); + } + + if(idx < jobs.length && q.isEmpty()) { + end = jobs[idx][0]; + q.offer(jobs[idx++]); + } + } + + + System.out.println(sum/jobs.length); + } +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java b/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java new file mode 100644 index 0000000..2fb22a8 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java @@ -0,0 +1,41 @@ +package Today_22_05_12; + +import java.util.*; + +public class rightbiggersoo { + + public static void main(String[] args) { + + int []A = {3,5,2,7}; + int[]answer = new int[A.length]; + + Stack ans = new Stack<>(); + Stack tmp = new Stack<>(); + + + for(int i = A.length-1 ; i > -1 ; i--) { + + int a = A[i]; + + while(!tmp.isEmpty() && a >= tmp.peek()) { + tmp.pop(); + } + + if(tmp.isEmpty()) { + ans.add(-1); + }else { + ans.add(tmp.peek()); + } + tmp.add(a); + + + } + + + for(int i =0;i() { + public int compare(int[]o1,int[]o2) { + + if(o1[1]==o2[1]) { + + return o1[0] - o2[0]; + } + return o1[1]-o2[1]; + + } + }); + + for(int i=0;i=end_time) { + end_time = rooms[i][1]; + count++; + } + } + + System.out.println(count); + } + +} From 8b6a676cb21f182b94686344a8530f9a04a73dcf Mon Sep 17 00:00:00 2001 From: monsileI Date: Sat, 14 May 2022 21:21:00 +0900 Subject: [PATCH 03/48] =?UTF-8?q?=EC=97=B0=EC=8A=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bfs.java | 2 +- .../bfsAgain.java | 2 +- .../combi_dfs.java | 2 +- .../dfs.java | 2 +- .../test.java | 2 +- .../twoPointer.java | 2 +- .../twoPointerRangeSum.java | 2 +- .../src/Today_22_05_12/fef.java | 51 +++++++++ .../src/Today_22_05_12/rightbiggersoo.java | 14 +-- .../src/Today_22_05_13/dictionary.java | 53 ++++++++++ .../src/Today_22_05_13/hideAndFind.java | 48 +++++++++ .../src/Today_22_05_13/practice.java | 47 ++++++++ .../src/Today_22_05_13/right.java | 41 +++++++ .../src/Today_22_05_13/soosick.java | 100 ++++++++++++++++++ .../src/Today_22_05_13/testCode.java | 25 +++++ 15 files changed, 377 insertions(+), 16 deletions(-) rename Basic_Of_Algorithm/src/{Today22_05_11 => Today_22_05_11}/bfs.java (98%) rename Basic_Of_Algorithm/src/{Today22_05_11 => Today_22_05_11}/bfsAgain.java (98%) rename Basic_Of_Algorithm/src/{Today22_05_11 => Today_22_05_11}/combi_dfs.java (97%) rename Basic_Of_Algorithm/src/{Today22_05_11 => Today_22_05_11}/dfs.java (97%) rename Basic_Of_Algorithm/src/{Today22_05_11 => Today_22_05_11}/test.java (98%) rename Basic_Of_Algorithm/src/{Today22_05_11 => Today_22_05_11}/twoPointer.java (98%) rename Basic_Of_Algorithm/src/{Today22_05_11 => Today_22_05_11}/twoPointerRangeSum.java (96%) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_12/fef.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_13/dictionary.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_13/hideAndFind.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_13/practice.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_13/right.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_13/soosick.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_13/testCode.java diff --git a/Basic_Of_Algorithm/src/Today22_05_11/bfs.java b/Basic_Of_Algorithm/src/Today_22_05_11/bfs.java similarity index 98% rename from Basic_Of_Algorithm/src/Today22_05_11/bfs.java rename to Basic_Of_Algorithm/src/Today_22_05_11/bfs.java index 1d7af4b..117d37f 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/bfs.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/bfs.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.LinkedList; import java.util.Queue; diff --git a/Basic_Of_Algorithm/src/Today22_05_11/bfsAgain.java b/Basic_Of_Algorithm/src/Today_22_05_11/bfsAgain.java similarity index 98% rename from Basic_Of_Algorithm/src/Today22_05_11/bfsAgain.java rename to Basic_Of_Algorithm/src/Today_22_05_11/bfsAgain.java index 0a1800b..bca547d 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/bfsAgain.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/bfsAgain.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.LinkedList; import java.util.Queue; diff --git a/Basic_Of_Algorithm/src/Today22_05_11/combi_dfs.java b/Basic_Of_Algorithm/src/Today_22_05_11/combi_dfs.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_11/combi_dfs.java rename to Basic_Of_Algorithm/src/Today_22_05_11/combi_dfs.java index 693874f..4d9802b 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/combi_dfs.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/combi_dfs.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; public class combi_dfs { diff --git a/Basic_Of_Algorithm/src/Today22_05_11/dfs.java b/Basic_Of_Algorithm/src/Today_22_05_11/dfs.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_11/dfs.java rename to Basic_Of_Algorithm/src/Today_22_05_11/dfs.java index 3190a0d..f468513 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/dfs.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/dfs.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; public class dfs { diff --git a/Basic_Of_Algorithm/src/Today22_05_11/test.java b/Basic_Of_Algorithm/src/Today_22_05_11/test.java similarity index 98% rename from Basic_Of_Algorithm/src/Today22_05_11/test.java rename to Basic_Of_Algorithm/src/Today_22_05_11/test.java index d86f3b7..82b89ad 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/test.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/test.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.*; diff --git a/Basic_Of_Algorithm/src/Today22_05_11/twoPointer.java b/Basic_Of_Algorithm/src/Today_22_05_11/twoPointer.java similarity index 98% rename from Basic_Of_Algorithm/src/Today22_05_11/twoPointer.java rename to Basic_Of_Algorithm/src/Today_22_05_11/twoPointer.java index 202e7d6..9fc63d5 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/twoPointer.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/twoPointer.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.Arrays; diff --git a/Basic_Of_Algorithm/src/Today22_05_11/twoPointerRangeSum.java b/Basic_Of_Algorithm/src/Today_22_05_11/twoPointerRangeSum.java similarity index 96% rename from Basic_Of_Algorithm/src/Today22_05_11/twoPointerRangeSum.java rename to Basic_Of_Algorithm/src/Today_22_05_11/twoPointerRangeSum.java index e515221..802aa0a 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/twoPointerRangeSum.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/twoPointerRangeSum.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.Arrays; diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/fef.java b/Basic_Of_Algorithm/src/Today_22_05_12/fef.java new file mode 100644 index 0000000..84cd39f --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/fef.java @@ -0,0 +1,51 @@ +package Today_22_05_12; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.Stack; + +public class fef { + + public static void main(String[] args) { + + + int[][] rooms = {{1,4},{3,5},{0,6},{5,7},{3,8}, + {5,9},{6,10},{8,11},{8,12},{2,13}, + {12,14},{11,14}}; + + int answer = 0; + + Arrays.sort(rooms,new Comparator() { + + @Override + public int compare(int[] o1, int[] o2) { + + if(o1[1]==o2[1]) { + return o1[0] - o2[0]; + } + return o1[1]-o2[1]; + } + + }); + + for(int i=0;i=end_time) { + end_time = rooms[i][1]; + count++; + } + + + } + + System.out.println("답 : " + count); + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java b/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java index 2fb22a8..924108d 100644 --- a/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java +++ b/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java @@ -12,12 +12,11 @@ public static void main(String[] args) { Stack ans = new Stack<>(); Stack tmp = new Stack<>(); - - for(int i = A.length-1 ; i > -1 ; i--) { + for(int i = A.length-1; i > -1 ; i--) { - int a = A[i]; + int num = A[i]; - while(!tmp.isEmpty() && a >= tmp.peek()) { + while(!tmp.isEmpty() && (num >= tmp.peek())) { tmp.pop(); } @@ -26,16 +25,13 @@ public static void main(String[] args) { }else { ans.add(tmp.peek()); } - tmp.add(a); + tmp.add(num); } + for(int i = 0 ; i < answer.length;i++) System.out.println(ans.pop()); - for(int i =0;i dic = new ArrayList<>(); + ArrayList ans = new ArrayList<>(); + + String alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + dic.add("&&"); + + for(int i=0;i q = new LinkedList<>(); + + int[]check = new int[100001]; + + check[finder] = 0; + + q.add(finder); + + while(!q.isEmpty()) { + + int pos = q.poll(); + + if(check[hider]!=0 || pos>100000) break; + + if(pos-1 >= 0 && check[pos-1] ==0 ) { + check[pos-1] = check[pos] + 1; + q.add(pos-1); + } + if(pos+1 < check.length && check[pos-1] ==0 ) { + check[pos+1] = check[pos] + 1; + q.add(pos+1); + } + if(pos*2 >= 0 && check[pos*2] ==0 ) { + check[pos*2] = check[pos] + 1; + q.add(pos*2); + } + + } + + + System.out.println(check[hider]); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_13/practice.java b/Basic_Of_Algorithm/src/Today_22_05_13/practice.java new file mode 100644 index 0000000..e2bcd16 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_13/practice.java @@ -0,0 +1,47 @@ +package Today_22_05_13; + +import java.util.Comparator; +import java.util.Arrays; + +public class practice { + + public static void main(String[] args) { + + int[][] rooms = {{1,4},{3,5},{0,6},{5,7},{3,8}, + {5,9},{6,10},{8,11},{8,12},{2,13}, + {12,14}}; + + + Arrays.sort(rooms,new Comparator() { + + @Override + public int compare(int[] o1, int[] o2) { + // TODO Auto-generated method stub + if(o1[1]==o2[1]) { + return o1[0]-o2[0]; + } + return o1[1]-o2[1]; + } + + }); + + + + int end_time = 0; + int count = 0; + + + for(int i=0;i=end_time) { + end_time = rooms[i][1]; + count++; + } + + } + + + System.out.println(count); + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_13/right.java b/Basic_Of_Algorithm/src/Today_22_05_13/right.java new file mode 100644 index 0000000..b826d66 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_13/right.java @@ -0,0 +1,41 @@ +package Today_22_05_13; + +import java.util.Stack; + +public class right { + + public static void main(String[] args) { + + int [] arr = {3,5,1,7}; + + Stack temp = new Stack<>(); + Stack ans = new Stack<>(); + + + + for(int i=arr.length-1;i>-1;i--) { + + int num = arr[i]; + + while(!temp.isEmpty() && num>=temp.peek()) { + temp.pop(); + } + + if(temp.isEmpty()) { + ans.add(-1); + }else { + ans.add(temp.peek()); + } + temp.add(num); + + } + + int []result = new int[arr.length]; + + for(int i=0;i opArr = new ArrayList<>(); + static ArrayList numArr = new ArrayList<>(); + + + public static void main(String[] args) { + + String expression = "100-200*300-500+20"; + + input(expression); + + dfs(new char[3],0); + + System.out.println(answer); + + + + } + + static Long change(char ch,long a, long b) { + if(ch=='+') return a+b; + else if(ch=='-') return a-b; + else if(ch=='*') return a*b; + else return (long) 0; + + } + + + static void dfs(char[]p,int count) { + + if(count==3) { + + ArrayListnumList =new ArrayList<>(numArr); + ArrayListopList =new ArrayList<>(opArr); + + for(int i=0;i='0'&& ch<='9') num += ch; + else { + numArr.add(Long.parseLong(num)); + opArr.add(ch); + num=""; + } + + + + } + + numArr.add(Long.parseLong(num)); + + + } + + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_13/testCode.java b/Basic_Of_Algorithm/src/Today_22_05_13/testCode.java new file mode 100644 index 0000000..698046c --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_13/testCode.java @@ -0,0 +1,25 @@ +package Today_22_05_13; + +import java.util.Stack; + +public class testCode { + + public static void main(String[] args) { + + int n = 43674; + int k = 3; + int answer = 0; + + String num = ""; + + while(n>0) { + + num = n%k + num; + n /= k; + + } + + System.out.println(num); + + } +} From 22bdf6d56b52f3f796b4e2e34a3bffa97b756364 Mon Sep 17 00:00:00 2001 From: monsileI Date: Sun, 15 May 2022 23:16:26 +0900 Subject: [PATCH 04/48] small test --- .../src/Today_22_05_15/bfs.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_15/bfs.java diff --git a/Basic_Of_Algorithm/src/Today_22_05_15/bfs.java b/Basic_Of_Algorithm/src/Today_22_05_15/bfs.java new file mode 100644 index 0000000..949ae98 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_15/bfs.java @@ -0,0 +1,57 @@ +package Today_22_05_15; + +import java.util.LinkedList; +import java.util.Queue; + +public class bfs { + + public static void main(String[] args) { + + int sb = 5; + int bro = 17; + + + + Queue q = new LinkedList<>(); + + int[] position = new int[100001]; + + + position[sb] = 0; + + q.add(sb); + + while(!q.isEmpty()) { + + + int p = q.poll(); + + if(position[bro]!=0) break; + + if(position[p-1] ==0 && p-1>=0) { + position[p-1] = position[p] + 1; + q.add(p-1); + } + + if(position[p+1] ==0 && p+1<=position.length) { + position[p+1] = position[p] + 1; + q.add(p+1); + + } + if(position[p*2] ==0 && p*2<=position.length) { + position[p*2] = position[p] + 1; + q.add(p*2); + + } + + + } + + if(sb==bro) position[bro] = 0; + System.out.println(position[bro] + " 초"); + + + + } + +} From e46107e34a3cc3e2d241002919a347cfe81e4d94 Mon Sep 17 00:00:00 2001 From: monsileI Date: Mon, 16 May 2022 18:52:03 +0900 Subject: [PATCH 05/48] =?UTF-8?q?bfs=20=EC=A4=91=EC=A0=90=EC=A0=81?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EA=B3=B5=EB=B6=80=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today_22_05_16/test.java | 51 +++++++++++++++++ .../src/Today_22_05_16/test2.java | 56 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_16/test.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_16/test2.java diff --git a/Basic_Of_Algorithm/src/Today_22_05_16/test.java b/Basic_Of_Algorithm/src/Today_22_05_16/test.java new file mode 100644 index 0000000..f01b73d --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_16/test.java @@ -0,0 +1,51 @@ +package Today_22_05_16; + +import java.util.LinkedList; +import java.util.Queue; + +public class test { + + public static void main(String[] args) { + + int a = 5; + int b = 17; + + int[]visited = new int[10001]; + + + Queue q = new LinkedList<>(); + + visited[a] = 0; + + q.add(a); + + while(!q.isEmpty()) { + + int now = q.poll(); + + if(visited[b]!=0 || now >=10000) break; + + if(now-1>=0 && visited[now-1] ==0) { + visited[now-1] = visited[now] + 1; + q.add(now-1); + } + + if(now+1<=10000 && visited[now+1] ==0) { + visited[now+1] = visited[now] + 1; + q.add(now+1); + } + + if(now*2<=10000 && visited[now*2] ==0) { + visited[now*2] = visited[now] + 1; + q.add(now*2); + } + + } + + + + System.out.println(visited[b]); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_16/test2.java b/Basic_Of_Algorithm/src/Today_22_05_16/test2.java new file mode 100644 index 0000000..6b7cce6 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_16/test2.java @@ -0,0 +1,56 @@ +package Today_22_05_16; + +import java.util.Queue; +import java.util.LinkedList; + +public class test2 { + + public static void main(String[] args) { + + + int [][] map = {{1,0,1,1,1},{1,0,1,0,1},{1,0,1,1,1},{1,1,1,0,1},{0,0,0,0,1}}; + + + Queue q = new LinkedList<>(); + + int [][] temp = new int[map.length][map[0].length]; + + temp[0][0] = 1; + + q.add(new int[] {0,0}); + + int [][] move = {{0,1},{1,0},{0,-1},{-1,0}}; + + while(!q.isEmpty()) { + + int []c = q.poll(); + + int ci = c[0]; + int cj = c[1]; + + for(int d=0;d<4;d++) { + + int ni = ci + move[d][0]; + int nj = cj + move[d][1]; + + if(ni<0||nj<0||map.length-1 Date: Wed, 18 May 2022 17:09:42 +0900 Subject: [PATCH 06/48] =?UTF-8?q?level=5F1=20and=202=20kakao=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EC=A4=91=EC=8B=AC=EC=9C=BC=EB=A1=9C=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EC=97=B0=EC=8A=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/programmers_level_01/no_1.java | 69 +++++++++++++ .../src/programmers_level_01/no_2.java | 30 ++++++ .../src/programmers_level_01/no_3.java | 22 +++++ .../src/programmers_level_01/no_4.java | 54 +++++++++++ .../src/programmers_level_01/no_5.java | 45 +++++++++ .../src/programmers_level_01/no_6.java | 52 ++++++++++ .../src/programmers_level_01/no_7.java | 68 +++++++++++++ .../src/programmers_level_2/no_1.java | 53 ++++++++++ .../src/programmers_level_2/no_2.java | 54 +++++++++++ .../src/programmers_level_2/no_4.java | 71 ++++++++++++++ .../src/programmers_level_2/no_5.java | 84 ++++++++++++++++ .../src/programmers_level_2/no_7.java | 54 +++++++++++ .../src/programmers_level_2/no_8.java | 87 +++++++++++++++++ .../src/programmers_level_2/no_9.java | 97 +++++++++++++++++++ 14 files changed, 840 insertions(+) create mode 100644 Basic_Of_Algorithm/src/programmers_level_01/no_1.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_01/no_2.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_01/no_3.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_01/no_4.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_01/no_5.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_01/no_6.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_01/no_7.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_1.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_2.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_4.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_5.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_7.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_8.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_9.java diff --git a/Basic_Of_Algorithm/src/programmers_level_01/no_1.java b/Basic_Of_Algorithm/src/programmers_level_01/no_1.java new file mode 100644 index 0000000..98b3f78 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_01/no_1.java @@ -0,0 +1,69 @@ +package programmers_level_01; + +import java.util.HashMap; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; +public class no_1 { + + public static void main(String[] args) { + + String[]id_list = {"muzi", "frodo", "apeach", "neo"}; + String [] report = {"muzi frodo","apeach frodo","frodo neo","muzi neo","apeach muzi"}; + int k = 2; + + //나를 신고한 사람 리스트를 뽑음 + //그 사이즈가 2 이상이면 + //나를 신고한 사람한테 +1 + + int[]result = new int[id_list.length]; + + HashMap> singoList = new HashMap<>(); + //나를 신고한 사람 리스트 + HashMap myList = new HashMap<>(); + //내가 받을 매일 횟수 + + for(int i=0;i()); + myList.put(id_list[i], 0); + } + + for(int i=0;i=k) { + + System.out.println(singoList.get(key)); + + for(String str : singoList.get(key)) { + + myList.put(str, myList.get(str)+1); + + + } + } + + } + + for(int i=0;i15) { + new_id = new_id.substring(0,15); + new_id = new_id.replaceAll("[.]$", ""); + } + + if(new_id.length()<3) { + while(new_id.length()<3) { + new_id += new_id.charAt(new_id.length()-1); + } + } + + System.out.println(new_id); + + } +} diff --git a/Basic_Of_Algorithm/src/programmers_level_01/no_3.java b/Basic_Of_Algorithm/src/programmers_level_01/no_3.java new file mode 100644 index 0000000..3b15d80 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_01/no_3.java @@ -0,0 +1,22 @@ +package programmers_level_01; + +public class no_3 { + + public static void main(String[] args) { + + String s = "one4seveneight"; + int answer = 0; + + String [] alpha = {"zero","one","two","three","four","five","six","seven","eight","nine"}; + + + for(int i=0;i stack = new Stack<>(); + + for(int i=0;i fail_rate = new ArrayList<>(); + + int cnt = 0; + + for(int i=1;i<=n;i++) { + for(int j=0;jDouble.compare(b[1], a[1])); + + for(int i=0;i s.length() ? s.length() : i * (j+1); + + now = next; + next = s.substring(start,end); + + if(now.equals(next)) { + hit++; + }else { + result += processHit(hit) + now; + hit = 1; + } + + + + + } + + result += processHit(hit) + next; + + System.out.println(result); + + answer = Math.min(answer, result.length()); + } + + + System.out.println(answer); + + + + } + static String processHit(int hit) { + return hit > 1 ? String.valueOf(hit) : ""; + } + +} diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_2.java b/Basic_Of_Algorithm/src/programmers_level_2/no_2.java new file mode 100644 index 0000000..67169a0 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_2.java @@ -0,0 +1,54 @@ +package programmers_level_2; + +import java.util.ArrayList; +import java.util.HashMap; + +public class no_2 { + + 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<>(); + + HashMap map = new HashMap<>(); + + for(String str : record) { + + String[]temp = str.split(" "); + + String action = temp[0]; + if(action.equals("Leave")) continue; + String id = temp[1]; + String nick = temp[2]; + + map.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 = map.get(id); + + String ans = nick+"님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + + } + + String[]answer = new String[answerList.size()]; + + + for(int i=0;i2"}; + + + datas = data.clone(); + + boolean[]visited = new boolean[member.length]; + + dfs(visited,""); + + System.out.println(answer); + + } + static void dfs(boolean[]visited,String now) { + + if(now.length()==member.length) { + if(check(now)) answer++; + + return; + } + + + for(int i=0;i') { + if(!(Math.abs(pos1-pos2)>idx+1)) return false; + }else if(ch=='<') { + if(!(Math.abs(pos1-pos2) map = new HashMap<>(); + static ArrayList answerList = new ArrayList<>(); + + public static void main(String[] args) { + + String[] orders = {"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}; + int [] course = {2,3,4}; + + for(int i=0;i list = new ArrayList<>(map.values()); + int max = Collections.max(list); + if(max>1) { + for(String key : map.keySet()) { + if(map.get(key)==max) { + answerList.add(key); + } + } + + } + + + + } + + + map.clear(); + } + + String[]answer = new String[answerList.size()]; + + Collections.sort(answerList); + + for(int i=0;i arr1 = new ArrayList<>(); + ArrayList arr2 = new ArrayList<>(); + + + + for(int i=0;i='a'&&first<='z')&&(second>='a'&&second<='z')) { + arr1.add(""+first+second); + } + } + + for(int i=0;i='a'&&first<='z')&&(second>='a'&&second<='z')) { + arr2.add(""+first+second); + } + } + double son = 0; + double mom = 0; + + mom = arr1.size() + arr2.size(); + + System.out.println(mom); + + for(int i=0;i numArr = new ArrayList<>(); + static ArrayList opArr = new ArrayList<>(); + static char[]op = {'+','-','*'}; + static long answer = Integer.MIN_VALUE; + static boolean[]visited = new boolean[3]; + + public static void main(String[] args) { + + String expression = "100-200*300-500+20"; + + change(expression); + + dfs(new char[3] ,0); + + System.out.println(answer); + + } + + static Long changeNum(char ch , long a, long b) { + + if(ch=='+') return a+b; + else if(ch=='*') return a*b; + else if(ch=='-') return a-b; + + return (long) 0; + } + + static void dfs(char[]p,int count) { + + if(count==3) { + + ArrayList numList = new ArrayList<>(numArr); + ArrayList opList = new ArrayList<>(opArr); + + for(int i=0;i='0'&&ch<='9') { + num += ch; + }else { + numArr.add(Long.parseLong(num)); + opArr.add(ch); + num = ""; + + } + + } + + numArr.add(Long.parseLong(num)); + + } +} From a5eb7c24d93e877952582f9ee9dcc70ed1ea3aab Mon Sep 17 00:00:00 2001 From: monsileI Date: Thu, 19 May 2022 21:13:08 +0900 Subject: [PATCH 07/48] =?UTF-8?q?=EB=A0=88=EB=B2=A8=202=20,=20sql=20?= =?UTF-8?q?=EC=97=B0=EC=8A=B5=20=EC=9C=84=EC=A3=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today_22_05_19/menuRenew.java | 75 ++++++++++++++++ .../src/Today_22_05_19/rankingSearching.java | 82 ++++++++++++++++++ .../src/Today_22_05_19/soosick.java | 85 +++++++++++++++++++ 3 files changed, 242 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_19/menuRenew.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_19/rankingSearching.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_19/soosick.java diff --git a/Basic_Of_Algorithm/src/Today_22_05_19/menuRenew.java b/Basic_Of_Algorithm/src/Today_22_05_19/menuRenew.java new file mode 100644 index 0000000..20d1cf6 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_19/menuRenew.java @@ -0,0 +1,75 @@ +package Today_22_05_19; + +import java.util.HashMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +public class menuRenew { + + static HashMap map = new HashMap<>(); + static ArrayList answerList = new ArrayList<>(); + + public static void main(String[] args) { + + String [] orders = {"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}; + int [] course = {2,3,4}; + + for(int i=0;i maxValue = new ArrayList<>(map.values()); + int max = Collections.max(maxValue); + if(max>1) { + for(String key : map.keySet()) { + if(map.get(key)==max) { + answerList.add(key); + } + } + } + } + + + map.clear(); + } + + Collections.sort(answerList); + + String[]answer = new String[answerList.size()]; + + for(int i=0;i> map = new HashMap<>(); + + + public static void main(String[] args) { + + String [] info = {"java backend junior pizza 150","python frontend senior chicken 210","python frontend senior chicken 150","cpp backend senior pizza 260","java backend junior chicken 80","python backend senior chicken 50"}; + String [] query = {"java and backend and junior and pizza 100","python and frontend and senior and chicken 200","cpp and - and senior and pizza 250","- and backend and senior and - 150","- and - and - and chicken 100","- and - and - and - 150"}; + int [] answer = new int[query.length]; + + for(String str : info) { + String []temp = str.split(" "); + dfs(temp,"",0); + } + + for(String key:map.keySet()) { + Collections.sort(map.get(key)); + } + + for(int i =0;i list = map.get(now); + + int score = Integer.parseInt(infoScore); + + int start = 0, end = list.size()-1; + + while(start<=end) { + + int mid = (start+end)/2; + + if(list.get(mid)()); + } + map.get(now).add(Integer.parseInt(temp[4])); + return; + } + + dfs(temp,now+"-",count+1); + dfs(temp,now+temp[count],count+1); + + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_19/soosick.java b/Basic_Of_Algorithm/src/Today_22_05_19/soosick.java new file mode 100644 index 0000000..db211b1 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_19/soosick.java @@ -0,0 +1,85 @@ +package Today_22_05_19; + +import java.util.*; + +public class soosick { + + static long answer = 0; + static ArrayList numList = new ArrayList<>(); + static ArrayList opList = new ArrayList<>(); + static char [] op = {'+','-','*'}; + static boolean []visited = new boolean[3]; + + public static void main(String[] args) { + + String expression = "100-200*300-500+20"; + + String num = ""; + for(int i=0;i='0' && ch <= '9') { + num += ch; + }else { + numList.add(Long.parseLong(num)); + num=""; + opList.add(ch); + } + } + + numList.add(Long.parseLong(num)); + + dfs(new char[3],0); + + System.out.println(answer); + } + + static Long change(char ch , long a, long b) { + if(ch=='+') return a + b; + else if(ch=='*') return a * b; + else if(ch=='-') return a - b; + else return (long)0; + } + + static void dfs(char[]p,int count) { + + if(count==3) { + ArrayList numArr = new ArrayList<>(numList); + ArrayList opArr = new ArrayList<>(opList); + + for(int i=0;i Date: Thu, 19 May 2022 21:33:07 +0900 Subject: [PATCH 08/48] merge test --- Basic_Of_Algorithm/src/Today_22_05_19/test.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_19/test.java diff --git a/Basic_Of_Algorithm/src/Today_22_05_19/test.java b/Basic_Of_Algorithm/src/Today_22_05_19/test.java new file mode 100644 index 0000000..dc91767 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_19/test.java @@ -0,0 +1,9 @@ +package Today_22_05_19; + +public class test { + + public static void main(String[] args) { + + System.out.println("Merge Test"); + } +} From e28db6f1c19deab84544c727fa50c1606c0bbdf2 Mon Sep 17 00:00:00 2001 From: monsileI Date: Fri, 20 May 2022 19:34:44 +0900 Subject: [PATCH 09/48] =?UTF-8?q?=EB=B0=B1=EC=A4=80=20=EA=B7=B8=EB=A6=AC?= =?UTF-8?q?=EB=94=94=20=EC=95=8C=EA=B3=A0=EB=A6=AC=EC=A6=98=20=EC=9C=84?= =?UTF-8?q?=EC=A3=BC=EB=A1=9C=20=EA=B3=B5=EB=B6=80!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today_22_05_20/bfs.java | 52 +++++++++++++++++++ .../src/Today_22_05_20/dungeons.java | 36 +++++++++++++ .../Today_22_05_20/greddy_changeMoney.java | 37 +++++++++++++ .../src/Today_22_05_20/greedy_atm.java | 33 ++++++++++++ .../src/Today_22_05_20/greedy_bracket.java | 39 ++++++++++++++ .../src/Today_22_05_20/greedy_coin.java | 43 +++++++++++++++ .../src/Today_22_05_20/greedy_coin2.java | 35 +++++++++++++ .../src/Today_22_05_20/greedy_sugar.java | 40 ++++++++++++++ .../src/Today_22_05_20/greedy_wordsMath.java | 42 +++++++++++++++ .../src/Today_22_05_20/room.java | 48 +++++++++++++++++ .../src/Today_22_05_20/tuple.java | 33 ++++++++++++ 11 files changed, 438 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/bfs.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/dungeons.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/greddy_changeMoney.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/greedy_atm.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/greedy_bracket.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/greedy_coin.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/greedy_coin2.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/greedy_sugar.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/greedy_wordsMath.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/room.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_20/tuple.java diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/bfs.java b/Basic_Of_Algorithm/src/Today_22_05_20/bfs.java new file mode 100644 index 0000000..2868715 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/bfs.java @@ -0,0 +1,52 @@ +package Today_22_05_20; + +import java.util.Queue; +import java.util.LinkedList; + +public class bfs { + + public static void main(String[] args) { + + int[][] maps = {{1,0,1,1,1},{1,0,1,0,1},{1,0,1,1,1},{1,1,1,0,1},{0,0,0,0,1}}; + int answer = 0; + + Queue q = new LinkedList<>(); + + int[][]temp = new int[maps.length][maps[0].length]; + + temp[0][0] = 1; + + q.add(new int[] {0,0}); + + int[][]move = {{0,1},{1,0},{0,-1},{-1,0}}; + + while(!q.isEmpty()) { + + int [] cur = q.poll(); + + int ni = cur[0]; + int nj = cur[1]; + + for(int d=0;d<4;d++) { + + int newI = ni + move[d][0]; + int newJ = nj + move[d][1]; + + if(newI<0||newJ<0||maps.length-1=arr[i]) { + + answer += cash/arr[i]; + cash = cash%arr[i]; + } + if(cash==0)break; + } + + + System.out.println(answer); + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/greedy_atm.java b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_atm.java new file mode 100644 index 0000000..50be8e6 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_atm.java @@ -0,0 +1,33 @@ +package Today_22_05_20; + +import java.util.Scanner; +import java.util.Arrays; + +public class greedy_atm { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int answer = 0; + + int n = scan.nextInt(); + + int[]man = new int[n]; + + for(int i=0;i=coin) { + System.out.println(coin); + answer++; + k -= coin; + } + + + } + + System.out.println(answer); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/greedy_coin2.java b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_coin2.java new file mode 100644 index 0000000..11d3b15 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_coin2.java @@ -0,0 +1,35 @@ +package Today_22_05_20; + +import java.util.Scanner; +import java.util.Arrays; +import java.util.Collections; +public class greedy_coin2 { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + + int n = scan.nextInt(); + int k = scan.nextInt(); + + int answer = 0; + + Integer[]arr = new Integer[n]; + + + for(int i=0;i-1;i--) { + + if(arr[i]<=k) { + answer += k/arr[i]; + k = k%arr[i]; + } + + } + + System.out.println(answer); + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/greedy_sugar.java b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_sugar.java new file mode 100644 index 0000000..8afced0 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_sugar.java @@ -0,0 +1,40 @@ +package Today_22_05_20; + +import java.io.InputStreamReader; +import java.io.BufferedReader; +public class greedy_sugar { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int n = Integer.parseInt(br.readLine()); + + //3 //5 + int answer = 0; + + //5의 배수도 3의 배수도 아닌 경우에도 나눠 떨어지는 애들이 있음! + + + while(true) { + + if(n%5==0) { + answer += n/5; + break; + }else { + answer ++; + n -= 3; + } + + if(n<0) { + answer = -1; + break; + } + + } + + System.out.println(answer); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/greedy_wordsMath.java b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_wordsMath.java new file mode 100644 index 0000000..1cd2aa4 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_wordsMath.java @@ -0,0 +1,42 @@ +package Today_22_05_20; + +import java.util.Scanner; + +public class greedy_wordsMath { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int n = scan.nextInt(); + + int[]arr = new int[n]; + + for(int i=0;i-1;i--) { + + int pre = arr[i]; + while(nPoint<=pre) { + + answer++; + pre--; + + } + + nPoint = pre; + + + } + + + System.out.println(answer); + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/room.java b/Basic_Of_Algorithm/src/Today_22_05_20/room.java new file mode 100644 index 0000000..279c1db --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/room.java @@ -0,0 +1,48 @@ +package Today_22_05_20; + +import java.util.Scanner; +import java.util.Arrays; +import java.util.Comparator; + +public class room { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int n = scan.nextInt(); + + int[][]arr = new int[n][2]; + + int answer = 0 ; + + for(int i=0;i() { + + @Override + public int compare(int[] o1, int[] o2) { + if(o1[1]==o2[1]) return o1[0] - o2[0]; + else return o1[1] - o2[1]; + } + }); + + int end_time = 0; + + for(int i=0;i map = new HashMap<>(); + + String [] splitString = s.split(","); + + for(int i=0;i keySet = new ArrayList<>(map.keySet()); + Collections.sort(keySet, (o1,o2)-> map.get(o2).compareTo(map.get(o1))); + + System.out.println(keySet); + + } +} From 61644af7ba101ec6c11ec4bf8af41951c43420ad Mon Sep 17 00:00:00 2001 From: monsileI Date: Sun, 22 May 2022 21:05:42 +0900 Subject: [PATCH 10/48] bfs vs dfs --- Basic_Of_Algorithm/src/test/bfs.java | 55 +++++++++++++++++++++++++++ Basic_Of_Algorithm/src/test/dddd.java | 41 ++++++++++++++++++++ Basic_Of_Algorithm/src/test/dfs.java | 16 ++++++++ 3 files changed, 112 insertions(+) create mode 100644 Basic_Of_Algorithm/src/test/bfs.java create mode 100644 Basic_Of_Algorithm/src/test/dddd.java create mode 100644 Basic_Of_Algorithm/src/test/dfs.java diff --git a/Basic_Of_Algorithm/src/test/bfs.java b/Basic_Of_Algorithm/src/test/bfs.java new file mode 100644 index 0000000..f7c49cd --- /dev/null +++ b/Basic_Of_Algorithm/src/test/bfs.java @@ -0,0 +1,55 @@ +package test; + +import java.util.Queue; +import java.util.LinkedList; + +public class bfs { + + public static void main(String[] args) { + + int[][]maps = {{1,0,1,1,1},{1,0,1,0,1},{1,0,1,1,1},{1,1,1,0,1},{0,0,0,0,1}}; + + int answer = 0; + + + int[][]temp = new int[maps.length][maps[0].length]; + + temp[0][0] = 1; + + Queue q = new LinkedList<>(); + + int [][] move = {{0,1},{1,0},{0,-1},{-1,0}}; + + q.add(new int[]{0,0}); + + while(!q.isEmpty()) { + + int [] cur = q.poll(); + + int cI = cur[0]; + int cJ = cur[1]; + + for(int d=0;d<4;d++) { + + int newI = cI + move[d][0]; + int newJ = cJ + move[d][1]; + + + if(newI<0||newJ<0||maps.length-1 2 -> 3 -> 8 -> 6 -> 5 -> 4 -> 7 -> + } + static String bfs(int start, int[][] graph, boolean[] visited) { + // 탐색 순서를 출력하기 위한 용도 + StringBuilder sb = new StringBuilder(); + // BFS에 사용할 큐를 생성해줍니다. + Queue q = new LinkedList(); + // 큐에 BFS를 시작 할 노드 번호를 넣어줍니다. + q.offer(start); + // 시작노드 방문처리 + visited[start] = true; + // 큐가 빌 때까지 반복 + while(!q.isEmpty()) { + int nodeIndex = q.poll(); + sb.append(nodeIndex + " -> "); + //큐에서 꺼낸 노드와 연결된 노드들 체크 + for(int i=0; i Date: Tue, 24 May 2022 15:23:11 +0900 Subject: [PATCH 11/48] =?UTF-8?q?=EB=B0=B1=EC=A4=80=20=EA=B7=B8=EB=A6=AC?= =?UTF-8?q?=EB=94=94=20+=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98=EB=A8=B8?= =?UTF-8?q?=EC=8A=A4=20=EC=96=91=EA=B6=81=20,=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EC=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Today_22_05_24/backJoon_greedy_no1.java | 65 ++++++++++++++ .../Today_22_05_24/backJoon_greedy_no2.java | 59 +++++++++++++ .../Today_22_05_24/backJoon_greedy_no3.java | 33 ++++++++ .../Today_22_05_24/backJoon_greedy_no4.java | 58 +++++++++++++ .../Today_22_05_24/backJoon_greedy_no5.java | 18 ++++ .../Today_22_05_24/programmer_lv_2_no_1.java | 54 ++++++++++++ .../Today_22_05_24/programmer_lv_2_no_2.java | 56 +++++++++++++ .../Today_22_05_24/programmer_lv_2_no_3.java | 84 +++++++++++++++++++ .../Today_22_05_24/programmer_lv_2_no_4.java | 14 ++++ Basic_Of_Algorithm/src/test/dddd.java | 41 --------- Basic_Of_Algorithm/src/test/test1.java | 62 ++++++++++++++ 11 files changed, 503 insertions(+), 41 deletions(-) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no1.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no2.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no3.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no4.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no5.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_1.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_2.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_3.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_4.java delete mode 100644 Basic_Of_Algorithm/src/test/dddd.java create mode 100644 Basic_Of_Algorithm/src/test/test1.java diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no1.java b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no1.java new file mode 100644 index 0000000..2b0e920 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no1.java @@ -0,0 +1,65 @@ +package Today_22_05_24; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class backJoon_greedy_no1 { + + static int answer = -1; + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String n = br.readLine(); + + + + String str = String.valueOf(n); + + boolean[]visited = new boolean[str.length()]; + + + dfs(visited,str,"",0); + + System.out.println(String.valueOf(answer)); + + } + + static boolean check(String now) { + + int a = Integer.parseInt(now); + + if(a%30==0) return true; + else return false; + + + + } + + static void dfs(boolean[]visited,String str,String now,int count) { + + + if(count==str.length()) { + if(check(now)) { + answer = Math.max(answer, Integer.parseInt(now)); + } + return; + } + + for(int i=0;i=25) { + money -= 25; + a++; + } + else if(money>=10) { + money -= 10; + b++; + } + else if(money>=5) { + money -=5; + c++; + } + else { + money -= 1; + d++; + + } + + if(money<=0) break; + + } + + + System.out.println(a+" "+b+" "+c+" "+d); + + } + + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no3.java b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no3.java new file mode 100644 index 0000000..7d6812a --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no3.java @@ -0,0 +1,33 @@ +package Today_22_05_24; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class backJoon_greedy_no3 { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] input = br.readLine().split(""); + + int i = 0; + for(String checkA : input) { + if(i == 0 && checkA.equals("U")) i++; + if((i == 1 || i == 3) && checkA.equals("C")) i++; + if(i == 2 && checkA.equals("P")) i++; + } + if(i==4) { + System.out.println("I love UCPC"); + }else { + System.out.println("I hate UCPC"); + } + + + } + + + + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no4.java b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no4.java new file mode 100644 index 0000000..7e12d23 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no4.java @@ -0,0 +1,58 @@ +package Today_22_05_24; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class backJoon_greedy_no4 { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int answer = 0; + + int n = Integer.parseInt(br.readLine()); + + String s = br.readLine(); + + Integer []crain = new Integer[n]; + + for(int i=0;i q = new PriorityQueue<>(Collections.reverseOrder()); + + for(int i=0;icrain[0]) answer = -1; + else { + + while(!q.isEmpty()) { + + answer++; + + for(int i=0;i= q.peek()) q.poll(); + if(q.isEmpty()) break; + + } + + if(q.isEmpty()) break; + + } + } + + + System.out.println(answer); + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no5.java b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no5.java new file mode 100644 index 0000000..3ba6717 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no5.java @@ -0,0 +1,18 @@ +package Today_22_05_24; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class backJoon_greedy_no5 { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_1.java b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_1.java new file mode 100644 index 0000000..c3328b3 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_1.java @@ -0,0 +1,54 @@ +package Today_22_05_24; + +public class programmer_lv_2_no_1 { + + public static void main(String[] args) { + + + + String s = "aabbaccc"; + + int answer = Integer.MAX_VALUE; + + + for(int i=1;i<=s.length()/2;i++) { + + String result =""; + String next = ""; + String now = ""; + int hit = 1; + + for(int j=0;j<=s.length()/i;j++) { + + int start = i * j; + int end = i * ( j + 1 ) > s.length() ? s.length():i*(j+1) ; + + next = s.substring(start,end); + + if(now.equals(next)) { + hit++; + }else { + + result += processHit(hit) + now; + hit = 1; + } + now = next; + + + } + result += processHit(hit) + now; + + System.out.println(result + " : " + result.length() + " 개"); + + answer = Math.min(answer, result.length()); + } + + System.out.println("답 :" + answer+" 개 "); + + + } + static String processHit(int hit) { + return hit>1 ? String.valueOf(hit) : ""; + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_2.java b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_2.java new file mode 100644 index 0000000..20739be --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_2.java @@ -0,0 +1,56 @@ +package Today_22_05_24; + +import java.util.Queue; +import java.util.LinkedList; +import java.util.ArrayList; + +public class programmer_lv_2_no_2 { + + public static void main(String[] args) { + + int [] progresses = {95, 90, 99, 99, 80, 99}; + + int [] speeds = {1, 1, 1, 1, 1, 1}; + + Queue q = new LinkedList<>(); + + for(int i=0;i answerList = new ArrayList<>(); + + while(!q.isEmpty()) { + + int a = q.poll(); + + int answerInt = 1; + + while(!q.isEmpty() && a>= q.peek()) { + + answerInt++; + q.poll(); + } + + answerList.add(answerInt); + + } + + System.out.println(answerList); + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_3.java b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_3.java new file mode 100644 index 0000000..edb7701 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_3.java @@ -0,0 +1,84 @@ +package Today_22_05_24; + + +import java.util.ArrayList; +import java.util.Collections; + +public class programmer_lv_2_no_3 { + + static ArrayList answer = new ArrayList<>(); + static int[] ryan; + static int[] apeach; + static int N; + static int max = Integer.MIN_VALUE; + + + public static void main(String[] args) { + + int []info = {0,0,0,0,0,0,0,0,3,4,3}; + + int n = 10; + + apeach = info.clone(); + + ryan = new int[11]; + N = n; + apeach = info.clone(); + dfs(0, 0); + + Collections.sort(answer,(o1,o2)->{ + + + for(int i=apeach.length-1;i>-1;i--) { + if(o1[i]!=o2[i]) return o2[i]-o1[i]; + } + + + return 0; + }); + + for(int i : answer.get(0))System.out.print(i+","); + + } + + static void dfs(int s, int l) { + + if(l==N) { + int r = 0; + int a = 0; + + for(int i=0;ia) { + int diff = r - a; + if(diff>max) { + max = diff; + answer.clear(); + answer.add(ryan.clone()); + }else if(diff==max) { + answer.add(ryan.clone()); + } + + } + + + } + + else { + + for(int i=s;i 2 -> 3 -> 8 -> 6 -> 5 -> 4 -> 7 -> - } - static String bfs(int start, int[][] graph, boolean[] visited) { - // 탐색 순서를 출력하기 위한 용도 - StringBuilder sb = new StringBuilder(); - // BFS에 사용할 큐를 생성해줍니다. - Queue q = new LinkedList(); - // 큐에 BFS를 시작 할 노드 번호를 넣어줍니다. - q.offer(start); - // 시작노드 방문처리 - visited[start] = true; - // 큐가 빌 때까지 반복 - while(!q.isEmpty()) { - int nodeIndex = q.poll(); - sb.append(nodeIndex + " -> "); - //큐에서 꺼낸 노드와 연결된 노드들 체크 - for(int i=0; i q = new LinkedList<>(); + + q.add(new int[] {0,0}); + + int[][]move = {{0,1},{1,0},{0,-1},{-1,0}}; + + while(!q.isEmpty()) { + + int[]cur = q.poll(); + + int i = cur[0]; + int j = cur[1]; + + + + for(int d=0;d<4;d++) { + + int newI = i + move[d][0]; + int newJ = j + move[d][1]; + + + if(newI<0||newJ<0||maps.length-1 Date: Thu, 26 May 2022 18:41:45 +0900 Subject: [PATCH 12/48] =?UTF-8?q?=EC=99=84=EC=A0=84=20=ED=83=90=EC=83=89?= =?UTF-8?q?=20=EA=B3=B5=EB=B6=80=20=EC=9C=84=EC=A3=BC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today_22_05_26/backJoon_antenna.java | 55 ++++++++++ .../src/Today_22_05_26/backJoon_color.java | 85 +++++++++++++++ .../Today_22_05_26/backJoon_combination.java | 47 ++++++++ .../programmers_bruteForce.java | 70 ++++++++++++ .../src/Today_22_05_26/rightBigNumber.java | 39 +++++++ .../src/Today_22_05_26/test.java | 35 ++++++ .../src/Today_22_05_26/twoPointer.java | 48 +++++++++ .../src/Today_22_05_26/yangong.java | 102 ++++++++++++++++++ 8 files changed, 481 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_26/backJoon_antenna.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_26/backJoon_color.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_26/backJoon_combination.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_26/programmers_bruteForce.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_26/rightBigNumber.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_26/test.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_26/twoPointer.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_26/yangong.java diff --git a/Basic_Of_Algorithm/src/Today_22_05_26/backJoon_antenna.java b/Basic_Of_Algorithm/src/Today_22_05_26/backJoon_antenna.java new file mode 100644 index 0000000..2df6ec0 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_26/backJoon_antenna.java @@ -0,0 +1,55 @@ +package Today_22_05_26; + +import java.util.Scanner; + +import java.util.Arrays; + +public class backJoon_antenna { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int n = scan.nextInt(); + + int[]arr = new int[n]; + + for(int i=0;iset = new HashSet<>(); + + + public static void main(String[] args) { + + + String numbers = "17"; + + + + boolean[]visited = new boolean[numbers.length()]; + + dfs(numbers,visited,""); + + System.out.println(set.size()); + System.out.println(set); + + } + + static void dfs(String numbers,boolean [] visited,String now) { + + if(!now.isEmpty()) { + + + int temp = Integer.parseInt(now); + boolean flag = true; + + if(temp==2) flag = true; + else if(temp==1 || temp==0) flag = false; + + + for(int i=2;i<=Math.sqrt(temp);i++) { + + if(temp%i==0) { + flag = false; + break; + } + + } + + if(flag) set.add(temp); + } + + + + + for(int i = 0 ; i temp = new Stack<>(); + Stack pra = new Stack<>(); + + //5 3 2 2 0 + + for(int i=arr.length-1;i>-1;i--) { + + int num = arr[i]; + + while(!temp.isEmpty() && num>= temp.peek()) { + temp.pop(); + } + + if(temp.isEmpty()) { + pra.add(-1); + }else { + pra.add(temp.peek()); + } + + temp.add(num); + + + + + } + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_26/test.java b/Basic_Of_Algorithm/src/Today_22_05_26/test.java new file mode 100644 index 0000000..941152c --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_26/test.java @@ -0,0 +1,35 @@ +package Today_22_05_26; + +import java.util.*; + +public class test { + + public static void main(String[] args) { + + + int[]arr = {3,7,1,5}; + //-1 5 -1 7 stack + + Stacktemp = new Stack<>(); + Stackans = new Stack<>(); + + + for(int i=arr.length-1;i>-1;i--) { + + int num = arr[i]; + + + while(!temp.isEmpty()&&num>=temp.peek()) temp.pop(); + + + if(temp.isEmpty()) ans.add(-1); + else ans.add(temp.peek()); + + temp.add(num); + + } + + + System.out.println(ans); + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_26/twoPointer.java b/Basic_Of_Algorithm/src/Today_22_05_26/twoPointer.java new file mode 100644 index 0000000..4e8fd61 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_26/twoPointer.java @@ -0,0 +1,48 @@ +package Today_22_05_26; + +import java.util.*; + +public class twoPointer { + + public static void main(String[] args) { + + int [] two = {1,1,2,2,3,3}; + //1,1,2,2,3,5,7 + int target = 4; + int answer = 0; + //답 = 2 + int start = 0; + int end = two.length-1; + Arrays.sort(two); + + + + while(start<=end) { + + + int sum = two[start] + two[end]; + + if(sumanswerList = new ArrayList<>(); + + public static void main(String[] args) { + + int[] info = {2,1,1,1,0,0,0,0,0,0,0}; + int n = 5; + apeach = info.clone(); + ryan = new int[apeach.length]; + visited = new boolean[apeach.length]; + count = n; + + answer = solution(n,info); + + for(int i=0;iapeach[i]) r += 10 - i; + else a += 10 - i; + } + + + if(r>a) { + int diff = r-a; + if(max{ + for(int i=10;i>-1;i--) { + if(o1[i]!=o2[i]) return o2[i] - o1[i]; + } + return 0; + }); + + + if(answerList.isEmpty()) return new int[] {-1}; + + answer = new int[info.length]; + + for(int i=0;i Date: Fri, 27 May 2022 22:08:24 +0900 Subject: [PATCH 13/48] =?UTF-8?q?=ED=97=B7=EA=B0=88=EB=A6=AC=EB=8A=94=20?= =?UTF-8?q?=EC=97=AC=EB=9F=AC=EA=B0=80=EC=A7=80=20binarySearch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today22_05_27/binarySearchNo01.java | 73 ++++++++++++++++ .../src/Today22_05_27/binarySearchNo2.java | 86 +++++++++++++++++++ .../src/Today22_05_27/binarySearchNo3.java | 61 +++++++++++++ .../src/Today22_05_27/binarySearchNo4.java | 62 +++++++++++++ .../src/Today22_05_27/bracket.java | 52 +++++++++++ .../src/Today22_05_27/catchAndHide.java | 62 +++++++++++++ .../Today22_05_27/programmers_lv_2_no1.java | 62 +++++++++++++ .../Today22_05_27/programmers_lv_2_no2.java | 50 +++++++++++ .../src/Today22_05_27/rightBigNumber.java | 43 ++++++++++ .../Today_22_05_26/backJoon_number_card2.java | 71 +++++++++++++++ 10 files changed, 622 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo01.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo2.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo3.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo4.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/bracket.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/catchAndHide.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no1.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no2.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/rightBigNumber.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_26/backJoon_number_card2.java diff --git a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo01.java b/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo01.java new file mode 100644 index 0000000..6a02db3 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo01.java @@ -0,0 +1,73 @@ +package Today22_05_27; + +import java.util.Arrays; +import java.util.Scanner; + +public class binarySearchNo01 { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int n = scan.nextInt(); + + int[]arr = new int[n]; + + for(int i=0;i1) answer[i] = 1; + + } + + for(int i : answer)System.out.println(i); + + + } + + static int binary(int num,int[] arr) { + + + int start = 0; + int end = arr.length-1; + int count = 0; + + while(start<=end) { + + int mid = (start+end) / 2; + + if(num>=arr[mid]) start = mid+1; + else if(start==end)break; + else if(num=arr[mid]) start = mid+1; + else end = mid-1; + + } + + return start; + + } + + static int lowerSearch(int num, int []arr) { + + int start = 0; + int end = arr.length-1; + + while(start<=end) { + + + + int mid = (start+end)/2; + + + + if(num>arr[mid]) start = mid+1; + else end = mid-1; + + + + + } + + return start; + + } +} diff --git a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo3.java b/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo3.java new file mode 100644 index 0000000..fa7ef11 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo3.java @@ -0,0 +1,61 @@ +package Today22_05_27; + +import java.util.Scanner; +import java.util.Arrays; + +public class binarySearchNo3 { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int k = scan.nextInt(); + int n = scan.nextInt(); + + int[]arr = new int[k]; + + for(int i =0;i 0) { + temp += (arr[i]-mid); + } + } + + + if(temp stack = new Stack<>(); + + for(int j=0;jq = new LinkedList<>(); + + + q.add(new int[] {n,m,0}); + + + while(!q.isEmpty()) { + + int[]cur = q.poll(); + + int cn = cur[0]; + int cm = cur[1]; + + + if(cn==cm) break; + + if(cn>100000) break; + + + if(cm+1<10000 && check[cm+1]==0) { + check[cm+1] = check[cm] +1; + q.add(new int[] {cn,cm+1}); + } + + if(cm-1>0 && check[cm-1]==0) { + check[cm-1] = check[cm] +1; + q.add(new int[] {cn,cm-1}); + } + + if(cm*2<10000 && check[cm*2]==0) { + check[cm*2] = check[cm] +1; + q.add(new int[] {cn,cm*2}); + } + + } + + + System.out.println(check[n]); + + + + + } +} diff --git a/Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no1.java b/Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no1.java new file mode 100644 index 0000000..d9fece7 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no1.java @@ -0,0 +1,62 @@ +package Today22_05_27; + +public class programmers_lv_2_no1 { + + static int[]answer; + static int[]num = new int[2]; + + public static void main(String[] args) { + + + int[][]arr = {{1,1,1,1,1,1,1,1},{0,1,1,1,1,1,1,1},{0,0,0,0,1,1,1,1},{0,1,0,0,1,1,1,1},{0,0,0,0,0,0,1,1},{0,0,0,0,0,0,0,1},{0,0,0,0,1,0,0,1},{0,0,0,0,1,1,1,1}}; + + answer = new int[2]; + + + change(0,0,arr, arr.length); + + + + answer = num.clone(); + + System.out.println(answer[0]); + System.out.println(answer[1]); + } + + + static void change(int x,int y,int[][]arr,int size) { + + + if(check(x,y,arr,size)) { + num[arr[x][y]]++; + return; + } + + + + change(x, y,arr,size/2); + change(x+size/2, y,arr,size/2); + change(x, y+size/2,arr,size/2); + change(x+size/2, y+size/2,arr,size/2); + + + } + + static boolean check(int x,int y,int[][]arr,int size) { + + for(int i=x;i q = new PriorityQueue<>(); + + + for(int i : scoville) q.offer(i); + + + while(k>q.peek()) { + + if(q.size()<2)break; + + + int first = q.poll(); + int second = q.poll(); + + int newOne = first + (second*2); + + q.offer(newOne); + answer++; + + + } + + + System.out.println(answer); + + + + } + + + + +} diff --git a/Basic_Of_Algorithm/src/Today22_05_27/rightBigNumber.java b/Basic_Of_Algorithm/src/Today22_05_27/rightBigNumber.java new file mode 100644 index 0000000..35bf413 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today22_05_27/rightBigNumber.java @@ -0,0 +1,43 @@ +package Today22_05_27; + +import java.util.*; + +public class rightBigNumber { + + public static void main(String[] args) { + + int arr[] = {3,5,2,7}; + int []answer = new int[arr.length]; + + Stack tmp = new Stack<>(); + Stack ans = new Stack<>(); + + for(int i=arr.length-1;i>-1;i--) { + + int num = arr[i]; + + + while(!tmp.isEmpty() && num>=tmp.peek()) { + tmp.pop(); + } + + if(tmp.isEmpty()) { + ans.add(-1); + }else { + ans.add(tmp.peek()); + } + + tmp.add(num); + + + + + } + System.out.println(ans); + + for(int i=0;i=num) { + end = mid; + }else { + start = mid+1; + } + + } + + return start; + } + static int upperBound(int num,int []arr) { + + + int start = 0; + int end = arr.length; + + + while(startnum) { + end = mid; + }else { + start = mid+1; + } + + } + + return start; + } + +} From d9370113158813029437abe1f014e9a204b85516 Mon Sep 17 00:00:00 2001 From: monsileI Date: Sat, 28 May 2022 17:14:18 +0900 Subject: [PATCH 14/48] =?UTF-8?q?=EC=98=A4=EB=8A=98=20=EC=BD=94=ED=85=8C?= =?UTF-8?q?=EA=B0=80=20=EB=84=88=EB=AC=B4=20=EC=96=B4=EB=A0=A4=EC=9B=8C?= =?UTF-8?q?=EC=84=9C=20=ED=95=98=EB=8A=94=20=EC=89=AC=EB=8A=94=EB=82=A0?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EC=BD=94=ED=85=8C=20=EC=97=B0=EC=8A=B5=20?= =?UTF-8?q?=E3=85=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today22_05_27/bracket.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Basic_Of_Algorithm/src/Today22_05_27/bracket.java b/Basic_Of_Algorithm/src/Today22_05_27/bracket.java index 75d7d6c..bf8cfdf 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/bracket.java +++ b/Basic_Of_Algorithm/src/Today22_05_27/bracket.java @@ -2,51 +2,53 @@ import java.util.Stack; + public class bracket { public static void main(String[] args) { - String s = "[)(]"; + String s = "[](){}"; int answer = 0; + for(int i=0;i stack = new Stack<>(); + + Stackstack = new Stack<>(); for(int j=0;j Date: Sat, 28 May 2022 17:14:33 +0900 Subject: [PATCH 15/48] =?UTF-8?q?=EC=98=A4=EB=8A=98=20=EC=BD=94=ED=85=8C?= =?UTF-8?q?=EA=B0=80=20=EB=84=88=EB=AC=B4=20=EC=96=B4=EB=A0=A4=EC=9B=8C?= =?UTF-8?q?=EC=84=9C=20=ED=95=98=EB=8A=94=20=EC=89=AC=EB=8A=94=EB=82=A0?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EC=BD=94=ED=85=8C=20=EA=B3=B5=EB=B6=80=20?= =?UTF-8?q?=E3=85=A0=E3=85=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today22_05_27/disk.java | 67 +++++++++++++++++++ .../src/Today22_05_27/test.java | 41 ++++++++++++ .../src/Today22_05_27/test2.java | 30 +++++++++ 3 files changed, 138 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/disk.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/test.java create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/test2.java diff --git a/Basic_Of_Algorithm/src/Today22_05_27/disk.java b/Basic_Of_Algorithm/src/Today22_05_27/disk.java new file mode 100644 index 0000000..15b16ce --- /dev/null +++ b/Basic_Of_Algorithm/src/Today22_05_27/disk.java @@ -0,0 +1,67 @@ +package Today22_05_27; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.PriorityQueue; + +public class disk { + + public static void main(String[] args) { + + int[][]jobs = {{0, 3}, {1, 9}, {2, 6}}; + int answer = 0; + + Arrays.sort(jobs,(int[]o1,int[]o2)->{ + if(o1[0]==o2[0]) return o1[1] - o2[1]; + + return o1[0] - o2[0]; + }); + + for(int i=0;i q = new PriorityQueue<>(new Comparator() { + + @Override + public int compare(int[] o1, int[] o2) { + + return o1[1]-o2[1]; + } + + + }); + + q.offer(jobs[0]); + int end = jobs[0][0]; + int sum = 0; + int idx = 1; + + while(!q.isEmpty()) { + int [] cur = q.poll(); + end += cur[1]; + sum += end - cur[0]; + System.out.println(end + " end"); + System.out.println(sum); + + while(idx < jobs.length && jobs[idx][0] <= end) { + q.offer(jobs[idx++]); + } + + + + if(idx 0) sum += i-mid; + + if(sum Date: Sun, 29 May 2022 22:58:51 +0900 Subject: [PATCH 16/48] q --- .../src/Today22_05_27/quate.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today22_05_27/quate.java diff --git a/Basic_Of_Algorithm/src/Today22_05_27/quate.java b/Basic_Of_Algorithm/src/Today22_05_27/quate.java new file mode 100644 index 0000000..756557c --- /dev/null +++ b/Basic_Of_Algorithm/src/Today22_05_27/quate.java @@ -0,0 +1,55 @@ +package Today22_05_27; + +public class quate { + + static int [] answer = new int[2]; + + public static void main(String[] args) { + + + int [][] arr = {{1,1,1,1,1,1,1,1},{0,1,1,1,1,1,1,1},{0,0,0,0,1,1,1,1},{0,1,0,0,1,1,1,1},{0,0,0,0,0,0,1,1},{0,0,0,0,0,0,0,1},{0,0,0,0,1,0,0,1},{0,0,0,0,1,1,1,1}}; + + + + dfs(arr,arr.length,0,0); + + + System.out.println(answer[0]+" : "+answer[1]); + + } + + static boolean check(int[][]arr,int size,int x, int y) { + + for(int i=x;i Date: Tue, 31 May 2022 18:20:07 +0900 Subject: [PATCH 17/48] =?UTF-8?q?=EC=98=A4=EB=9E=9C=EB=A7=8C=EC=97=90=20?= =?UTF-8?q?=EC=BD=94=ED=85=8C=20=ED=8F=AD=EB=B0=9C=20=E3=85=8B=E3=85=8B?= =?UTF-8?q?=E3=85=8B=E3=85=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binarySearchNo01.java | 2 +- .../binarySearchNo2.java | 2 +- .../binarySearchNo3.java | 2 +- .../binarySearchNo4.java | 2 +- .../bracket.java | 2 +- .../catchAndHide.java | 2 +- .../disk.java | 2 +- .../programmers_lv_2_no1.java | 2 +- .../programmers_lv_2_no2.java | 2 +- .../quate.java | 2 +- .../rightBigNumber.java | 2 +- .../test.java | 2 +- .../test2.java | 2 +- .../src/Today_22_05_31/HowToLine.java | 58 ++++++++++ .../src/Today_22_05_31/Yangong.java | 87 +++++++++++++++ .../src/Today_22_05_31/apchuck.java | 56 ++++++++++ .../src/Today_22_05_31/changeBracket.java | 88 +++++++++++++++ .../src/Today_22_05_31/dungeon.java | 37 +++++++ .../src/Today_22_05_31/gameMap.java | 55 ++++++++++ .../src/Today_22_05_31/groupPicture.java | 66 ++++++++++++ .../src/Today_22_05_31/groupPicture2_BFS.java | 100 ++++++++++++++++++ .../src/Today_22_05_31/hanoi.java | 31 ++++++ .../src/Today_22_05_31/lastWordLinked.java | 52 +++++++++ .../src/Today_22_05_31/menuRenewal.java | 66 ++++++++++++ .../src/Today_22_05_31/parkingFee.java | 86 +++++++++++++++ .../src/Today_22_05_31/quad.java | 71 +++++++++++++ .../src/Today_22_05_31/soosick.java | 86 +++++++++++++++ .../src/Today_22_05_31/targetNumber.java | 36 +++++++ .../src/Today_22_05_31/treeCut.java | 37 +++++++ .../src/Today_22_05_31/tuple.java | 51 +++++++++ 30 files changed, 1076 insertions(+), 13 deletions(-) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/binarySearchNo01.java (97%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/binarySearchNo2.java (98%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/binarySearchNo3.java (96%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/binarySearchNo4.java (96%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/bracket.java (97%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/catchAndHide.java (97%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/disk.java (97%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/programmers_lv_2_no1.java (97%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/programmers_lv_2_no2.java (96%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/quate.java (97%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/rightBigNumber.java (96%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/test.java (95%) rename Basic_Of_Algorithm/src/{Today22_05_27 => Today_22_05_27}/test2.java (94%) create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/HowToLine.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/Yangong.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/apchuck.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/changeBracket.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/dungeon.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/gameMap.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/groupPicture.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/groupPicture2_BFS.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/hanoi.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/lastWordLinked.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/menuRenewal.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/parkingFee.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/quad.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/soosick.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/targetNumber.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/treeCut.java create mode 100644 Basic_Of_Algorithm/src/Today_22_05_31/tuple.java diff --git a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo01.java b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo01.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo01.java rename to Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo01.java index 6a02db3..542f282 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo01.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo01.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.Arrays; import java.util.Scanner; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo2.java b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo2.java similarity index 98% rename from Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo2.java rename to Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo2.java index c24629d..71237ec 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo2.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo2.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.Scanner; import java.util.Arrays; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo3.java b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo3.java similarity index 96% rename from Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo3.java rename to Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo3.java index fa7ef11..fee42cc 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo3.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo3.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.Scanner; import java.util.Arrays; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo4.java b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo4.java similarity index 96% rename from Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo4.java rename to Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo4.java index 1b8c8c3..e7a74c1 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/binarySearchNo4.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo4.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.Arrays; import java.util.Scanner; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/bracket.java b/Basic_Of_Algorithm/src/Today_22_05_27/bracket.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_27/bracket.java rename to Basic_Of_Algorithm/src/Today_22_05_27/bracket.java index bf8cfdf..9cfa93a 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/bracket.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/bracket.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.Stack; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/catchAndHide.java b/Basic_Of_Algorithm/src/Today_22_05_27/catchAndHide.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_27/catchAndHide.java rename to Basic_Of_Algorithm/src/Today_22_05_27/catchAndHide.java index 668bcd2..d22088c 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/catchAndHide.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/catchAndHide.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.*; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/disk.java b/Basic_Of_Algorithm/src/Today_22_05_27/disk.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_27/disk.java rename to Basic_Of_Algorithm/src/Today_22_05_27/disk.java index 15b16ce..3c1a0e1 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/disk.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/disk.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.Arrays; import java.util.Comparator; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no1.java b/Basic_Of_Algorithm/src/Today_22_05_27/programmers_lv_2_no1.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no1.java rename to Basic_Of_Algorithm/src/Today_22_05_27/programmers_lv_2_no1.java index d9fece7..51f7b7f 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no1.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/programmers_lv_2_no1.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; public class programmers_lv_2_no1 { diff --git a/Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no2.java b/Basic_Of_Algorithm/src/Today_22_05_27/programmers_lv_2_no2.java similarity index 96% rename from Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no2.java rename to Basic_Of_Algorithm/src/Today_22_05_27/programmers_lv_2_no2.java index b85744e..a333810 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/programmers_lv_2_no2.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/programmers_lv_2_no2.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.Queue; import java.util.LinkedList; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/quate.java b/Basic_Of_Algorithm/src/Today_22_05_27/quate.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_27/quate.java rename to Basic_Of_Algorithm/src/Today_22_05_27/quate.java index 756557c..1b48737 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/quate.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/quate.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; public class quate { diff --git a/Basic_Of_Algorithm/src/Today22_05_27/rightBigNumber.java b/Basic_Of_Algorithm/src/Today_22_05_27/rightBigNumber.java similarity index 96% rename from Basic_Of_Algorithm/src/Today22_05_27/rightBigNumber.java rename to Basic_Of_Algorithm/src/Today_22_05_27/rightBigNumber.java index 35bf413..b373088 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/rightBigNumber.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/rightBigNumber.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.*; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/test.java b/Basic_Of_Algorithm/src/Today_22_05_27/test.java similarity index 95% rename from Basic_Of_Algorithm/src/Today22_05_27/test.java rename to Basic_Of_Algorithm/src/Today_22_05_27/test.java index 013e93f..4f69622 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/test.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/test.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; import java.util.Queue; import java.util.LinkedList; diff --git a/Basic_Of_Algorithm/src/Today22_05_27/test2.java b/Basic_Of_Algorithm/src/Today_22_05_27/test2.java similarity index 94% rename from Basic_Of_Algorithm/src/Today22_05_27/test2.java rename to Basic_Of_Algorithm/src/Today_22_05_27/test2.java index dc990b4..8b39087 100644 --- a/Basic_Of_Algorithm/src/Today22_05_27/test2.java +++ b/Basic_Of_Algorithm/src/Today_22_05_27/test2.java @@ -1,4 +1,4 @@ -package Today22_05_27; +package Today_22_05_27; public interface test2 { diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/HowToLine.java b/Basic_Of_Algorithm/src/Today_22_05_31/HowToLine.java new file mode 100644 index 0000000..a52bcaa --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/HowToLine.java @@ -0,0 +1,58 @@ +package Today_22_05_31; + +public class HowToLine { + + static int check; + static String answer = ""; + public static void main(String[] args) { + + + int n = 3; + int k = 5; + + check = k; + + int[]arr = new int[n]; + + int num = 1; + + for(int i=0;i answerList = new ArrayList<>(); + static int maxValue = Integer.MIN_VALUE; + + public static void main(String[] args) { + + + int n = 10; + int[]info = {0,0,0,0,0,0,0,0,3,4,3}; + + apeach = info.clone(); + ryan = new int[apeach.length]; + + + arrow = n; + + dfs(0,0); + + + if(answerList.isEmpty()) answerList.add(new int[] {-1}); + else { + + Collections.sort(answerList,(o1,o2)-> { + + for(int i=o1.length-1;i>-1;i--) { + if(o1[i]!=o2[i]) return o2[i] - o1[i]; + } + + return 0; + + }); + + + } + + for(int i : answerList.get(0)) System.out.print(i+","); + + } + + static void dfs(int start,int goal) { + + if(goal==arrow) { + int r = 0; + int a = 0; + + for(int i=0;i=ryan[i]) a += 10 - i; + else r += 10-i; + + } + + if(r>a) { + int diff = r-a; + if(maxValue dic = new ArrayList<>(); + ArrayListans = new ArrayList<>(); + + dic.add("^&#("); + + for(int i=0;ist = new Stack<>(); + + for(int i=0;iq = new LinkedList<>(); + + int [][]temp = new int[maps.length][maps[0].length]; + + temp[0][0] = 1; + + q.add(new int[] {0,0}); + + int[][]move = {{0,1},{1,0},{0,-1},{-1,0}}; + + while(!q.isEmpty()) { + + int [] cur = q.poll(); + int i = cur[0]; + int j = cur[1]; + + for(int d = 0 ; d< 4; d++) { + + int newI = i + move[d][0]; + int newJ = j + move[d][1]; + + if(newI<0||newJ<0||maps.length-12"}; + dt = data; + dfs(0,""); + + System.out.println(answer); + + } + static boolean check(String now) { + + for(String str : dt) { + + int pos1 = now.indexOf(str.charAt(0)); + int pos2 = now.indexOf(str.charAt(2)); + int op = str.charAt(3); + int idx = str.charAt(4) - '0'; + + if(op=='=') { + if(!(Math.abs(pos1-pos2)==idx+1)) return false; + }else if(op=='>') { + if(!(Math.abs(pos1-pos2)>idx+1)) return false; + }else if(op=='<') { + if(!(Math.abs(pos1-pos2) " + to); + return; + } + + hanoi(n-1,start,to,mid); + + System.out.println(start+" -> " +to); + + hanoi(n-1,mid,start,to); + } +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/lastWordLinked.java b/Basic_Of_Algorithm/src/Today_22_05_31/lastWordLinked.java new file mode 100644 index 0000000..dd2b1cc --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/lastWordLinked.java @@ -0,0 +1,52 @@ +package Today_22_05_31; + +import java.util.ArrayList; + +public class lastWordLinked { + + public static void main(String[] args) { + + int n = 3; + + String [] words = {"tank", "kick", "know", "wheel", "land", "dream", "mother", "robot", "tank"}; + + int []answer = new int[2]; + + char last = words[0].charAt(words[0].length()-1); + + int person = 2; + int round = 1; + + ArrayListwordsList = new ArrayList<>(); + + wordsList.add(words[0]); + + for(int i=1;in) { + round++; + person = 1; + } + + } + + System.out.println(answer[0]+" : "+answer[1]); + + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/menuRenewal.java b/Basic_Of_Algorithm/src/Today_22_05_31/menuRenewal.java new file mode 100644 index 0000000..4981387 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/menuRenewal.java @@ -0,0 +1,66 @@ +package Today_22_05_31; + +import java.util.HashMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +public class menuRenewal { + + static HashMap map = new HashMap<>(); + static ArrayListanswerList = new ArrayList<>(); + + public static void main(String[] args) { + + String[]orders = {"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}; + int[]course = {2,3,4}; + + for(int i=0;imaxList = new ArrayList<>(map.values()); + int max = Collections.max(maxList); + if(max>1) { + for(String key : map.keySet()) { + if(max==map.get(key)) { + answerList.add(key); + } + } + } + } + + map.clear(); + } + + Collections.sort(answerList); + + System.out.println(answerList); + + } + static void dfs(int count,String order,String now) { + + if(count==0) { + map.put(now, map.getOrDefault(now, 0)+1); + return; + } + + for(int i=0;i map = new HashMap<>(); + static TreeMap tree = new TreeMap<>(); + + public static void main(String[] args) { + + int[]fees = {180,5000,10,600}; + String []records = {"05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT"}; + + + for(String str : records) { + + String [] temp = str.split(" "); + + int time = change(temp[0]); + String num = temp[1]; + String action = temp[2]; + + if(action.equals("IN")) map.put(num, time); + else { + + if(!tree.containsKey(num)) tree.put(num, 0); + + tree.put(num, tree.get(num) + (time - map.get(num))); + map.remove(num); + + } + } + + if(!map.isEmpty()) { + for(String key : map.keySet()) { + if(!tree.containsKey(key)) tree.put(key, 0); + + tree.put(key, tree.get(key) + ((23 * 60) + 59 - map.get(key))); + + } + } + + System.out.println(tree); + + ArrayList answerList = new ArrayList<>(); + + + + for(String key : tree.keySet()) { + + int time = tree.get(key); + + if(time<=fees[0]) { + answerList.add(fees[1]); + continue; + } + time -= fees[0]; + double result = fees[1]; + double check = (double)time/fees[2]; + + check = Math.ceil(check); + + result += fees[3] * check; + answerList.add((int)result); + + + } + + System.out.println(answerList); + + + } + static int change(String time) { + + String [] temp = time.split(":"); + + int hour = Integer.parseInt(temp[0]) * 60; + int min = Integer.parseInt(temp[1]) + hour; + + return min; + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/quad.java b/Basic_Of_Algorithm/src/Today_22_05_31/quad.java new file mode 100644 index 0000000..2a70cb0 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/quad.java @@ -0,0 +1,71 @@ +package Today_22_05_31; + +public class quad { + + + public static void main(String[] args) { + + solution solution = new solution(); + + int[][]arr1 = {{1,1,0,0},{1,0,0,0},{1,0,0,1},{1,1,1,1}}; + int[][]arr2 = {{1,1,1,1,1,1,1,1},{0,1,1,1,1,1,1,1},{0,0,0,0,1,1,1,1},{0,1,0,0,1,1,1,1},{0,0,0,0,0,0,1,1},{0,0,0,0,0,0,0,1},{0,0,0,0,1,0,0,1},{0,0,0,0,1,1,1,1}}; + int[]result1 = solution.solution(arr1); + int[]result2 = solution.solution(arr2); + + System.out.print(result1[0]+" , "); + System.out.println(result1[1]); + System.out.print(result2[0]+" , "); + System.out.println(result2[1]); + + } +} + +class solution{ + + + int[]answer; + + public int[]solution(int[][]arr) { + + answer= new int[2]; + + + + change(arr,0,0,arr.length); + + + + + + + return answer; + } + + boolean check(int[][]arr,int x,int y,int size) { + + for(int i=x;iopList = new ArrayList<>(); + static ArrayListnumList = new ArrayList<>(); + static long answer = 0; + + public static void main(String[] args) { + + + String expression = "100-200*300-500+20"; + + check(expression); + + boolean[]visited = new boolean[3]; + + dfs(new char[3],0,visited); + + System.out.println(answer); + + } + static long change(long a,long b,char ch) { + if(ch=='+')return a+b; + else if(ch=='-')return a-b; + else if(ch=='*')return a*b; + return 0; + } + static void dfs(char[]p,int num,boolean[]visited) { + + if(num==3) { + + ArrayList numArr = new ArrayList<>(numList); + ArrayList opArr = new ArrayList<>(opList); + + for(int i=0;i='0' && ch<='9') num += ch; + else { + numList.add(Long.parseLong(num)); + num=""; + opList.add(ch); + } + + } + + numList.add(Long.parseLong(num)); + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/targetNumber.java b/Basic_Of_Algorithm/src/Today_22_05_31/targetNumber.java new file mode 100644 index 0000000..1d0edf6 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/targetNumber.java @@ -0,0 +1,36 @@ +package Today_22_05_31; + +public class targetNumber { + + static int answer= 0; + static int tar; + public static void main(String[] args) { + + int[]numbers = {1,1,1,1,1}; + int target = 3; + tar = target; + dfs(numbers,0,0); + + System.out.println(answer); + + } + + static void dfs(int[]numbers,int now,int count) { + + if(count==numbers.length) { + + if(tar==now) answer++; + + + return; + } + + + dfs(numbers,now + numbers[count],count+1); + dfs(numbers,now - numbers[count],count+1); + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/treeCut.java b/Basic_Of_Algorithm/src/Today_22_05_31/treeCut.java new file mode 100644 index 0000000..d112dfc --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/treeCut.java @@ -0,0 +1,37 @@ +package Today_22_05_31; + +import java.util.Collections; + +public class treeCut { + + public static void main(String[] args) { + + int[]arr = {20,15,10,17}; + int cut = 7; + + int min = 0; + int max = 0; + + for(int i : arr) if(max0) count += i-mid; + + if(count>cut) min = mid+1; + else max = mid; + + + + } + + System.out.println(min); + + + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/tuple.java b/Basic_Of_Algorithm/src/Today_22_05_31/tuple.java new file mode 100644 index 0000000..ae995ca --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/tuple.java @@ -0,0 +1,51 @@ +package Today_22_05_31; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; + +public class tuple { + + public static void main(String[] args) { + + String s = "{{4,2,3},{3},{2,3,4,1},{2,3}}"; + + s = s.replaceAll("\\{", ""); + s = s.replaceAll("\\}", ""); + + + HashMap map = new HashMap<>(); + + String []temp = s.split(","); + + for(String str : temp) { + int num = Integer.parseInt(str); + map.put(num,map.getOrDefault(num, 0)+1); + } + + + ArrayList answerList = new ArrayList<>(map.keySet()); + + + Collections.sort(answerList, new Comparator() { + + @Override + public int compare(Integer o1, Integer o2) { + if(map.get(o1)==map.get(o2)) return map.get(o1)- map.get(o2); + else return map.get(o2)- map.get(o1); + } + + }); + + + + int[]answer= new int[answerList.size()]; + + for(int i=0;i Date: Wed, 1 Jun 2022 22:56:29 +0900 Subject: [PATCH 18/48] =?UTF-8?q?=EC=B9=B4=EC=B9=B4=EC=98=A4,=20=ED=95=B4?= =?UTF-8?q?=EC=8B=9C=20=EC=9C=84=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/programmers_level_01/crain.java | 56 +++++++++++++++++++ .../src/programmers_level_2/change.java | 38 +++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 Basic_Of_Algorithm/src/programmers_level_01/crain.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/change.java diff --git a/Basic_Of_Algorithm/src/programmers_level_01/crain.java b/Basic_Of_Algorithm/src/programmers_level_01/crain.java new file mode 100644 index 0000000..f43b4c5 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_01/crain.java @@ -0,0 +1,56 @@ +package programmers_level_01; + +import java.util.Stack; + +public class crain { + + public static void main(String[] args) { + + int[][] board = {{0,0,0,0,0},{0,0,1,0,3},{0,2,5,0,1},{4,2,4,4,2},{3,5,1,3,1}}; + int [] moves = {1,5,3,5,1,2,1,4}; + + int answer = 0; + + Stack stack = new Stack<>(); + + + for(int mov : moves) { + + mov--; + + for(int i=0;i> map = new HashMap<>(); + + for(int i=0;i()); + + map.get(second).add(first); + + } + + + + for(String key : map.keySet()) { + + answer *= map.get(key).size()+1; + } + + + + System.out.println(answer-1); + + + } +} From 4bee63bbea649e970b5587b6b26626d5d18d6dec Mon Sep 17 00:00:00 2001 From: monsileI Date: Thu, 2 Jun 2022 19:49:10 +0900 Subject: [PATCH 19/48] =?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(); + + } + + +} From b597316594d5d54a174c4b5a7b3abcec050eb065 Mon Sep 17 00:00:00 2001 From: monsileI Date: Fri, 3 Jun 2022 22:47:10 +0900 Subject: [PATCH 20/48] =?UTF-8?q?=EB=8B=A4=EC=9D=B5=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=9D=BC=EB=A7=8C=20=EB=B3=B5=EC=8A=B5=20=EC=96=B4=EB=A0=A4?= =?UTF-8?q?=EC=9B=8C=20=E3=85=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today_22_06_03/deliveryAgain.java | 84 +++++++++++++++++++ .../src/Today_22_06_03/dijikstra.java | 80 ++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_06_03/deliveryAgain.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_03/dijikstra.java diff --git a/Basic_Of_Algorithm/src/Today_22_06_03/deliveryAgain.java b/Basic_Of_Algorithm/src/Today_22_06_03/deliveryAgain.java new file mode 100644 index 0000000..b626408 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_03/deliveryAgain.java @@ -0,0 +1,84 @@ +package Today_22_06_03; + +public class deliveryAgain { + + public static void main(String[] args) { + + + int n = 3; + + int [][]road = {{1,2,1},{1,3,5},{2,3,1}}; + + int k = 2; + + int answer = 0; + + int [][] map = new int[n+1][n+1]; + + int INF = 500001; + + for(int i=1;i value) { + map[a][b] = value; + map[b][a] = value; + } + } + + + int[]dist = new int[n+1]; + + for(int i=2 ; i dist[min_idx] + map[min_idx][j]) { + dist[j] = dist[min_idx] + map[min_idx][j]; + } + } + + } + + for(int i = 1 ; i Date: Tue, 7 Jun 2022 20:08:18 +0900 Subject: [PATCH 21/48] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A42=EB=8B=A8=EA=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/programmers_level_2/no_10.java | 55 +++++++++++ .../src/programmers_level_2/no_11.java | 91 +++++++++++++++++++ .../src/programmers_level_2/no_12.java | 73 +++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_10.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_11.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_12.java diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_10.java b/Basic_Of_Algorithm/src/programmers_level_2/no_10.java new file mode 100644 index 0000000..ee3fd67 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_10.java @@ -0,0 +1,55 @@ +package programmers_level_2; + +import java.util.HashMap; +import java.util.ArrayList; + +public class no_10 { + + public static void main(String[] args) { + + + String [] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"}; + + HashMap map = new HashMap<>(); + ArrayList answerList = new ArrayList<>(); + + 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]; + + map.put(id, nick); + + } + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Change")) continue; + + String nick = map.get(id); + String ans = nick + "님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + } + + + String[]answer = new String[answerList.size()]; + + for(int i = 0 ; i< answerList.size();i++) answer[i] = answerList.get(i); + + for(String str : answer)System.out.println(str); + + + } + +} diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_11.java b/Basic_Of_Algorithm/src/programmers_level_2/no_11.java new file mode 100644 index 0000000..32904a6 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_11.java @@ -0,0 +1,91 @@ +package programmers_level_2; + +import java.util.ArrayList; +import java.util.Collections; + +public class no_11 { + + public static void main(String[] args) { + + + String m = "CC#BCC#BCC#BCC#B"; + String[]musicinfos = {"03:00,03:30,FOO,CC#B", "04:00,04:08,BAR,CC#BCC#BCC#B"}; + String answer = "(None)"; + + String []mel = {"C#","D#","E#","F#","G#","A#","B#"}; + String []melChange = {"c","d","e","f","g","a","b"}; + + ArrayListanswerList = new ArrayList<>(); + + for(int i=0;i{ + + String []a = o1.split(":"); + String []b = o2.split(":"); + + int aa = Integer.parseInt(a[1]); + int bb = Integer.parseInt(b[1]); + + if(aa>bb) return bb-aa; + + return 0; + }); + + + String [] temp = answerList.get(0).split(":"); + answer = temp[0]; + + System.out.println(answer); + } + + + + + + } + static int change(String start,String end) { + + String s[] = start.split(":"); + + int hour = Integer.parseInt(s[0]); + int StartMin = Integer.parseInt(s[1]) + hour*60; + + s = end.split(":"); + + hour = Integer.parseInt(s[0]); + int endMin = Integer.parseInt(s[1]) + hour*60; + + return endMin - StartMin; + + + + } + +} diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_12.java b/Basic_Of_Algorithm/src/programmers_level_2/no_12.java new file mode 100644 index 0000000..d16ce0f --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_12.java @@ -0,0 +1,73 @@ +package programmers_level_2; + +public class no_12 { + + public static void main(String[] args) { + + int n = 6; + int[][]road = {{1,2,1},{1,3,2},{2,3,2},{3,4,3},{3,5,2},{3,5,3},{5,6,1}}; + int k = 4; + int answer = 0; + int INF = 500001; + int [][] map = new int[n+1][n+1]; + + for(int i = 1 ; i <=n; i++) { + for(int j=1; j<=n ; j++) { + if(i==j) continue; + map[i][j] = INF; //무한대 + } + } + + + 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++; + } + System.out.println(answer); + for(int i : dist)System.out.print(i+","); + } + +} \ No newline at end of file From ba4ddf51c0c3421f3937f886a409afd96fb439bf Mon Sep 17 00:00:00 2001 From: monsileI Date: Wed, 8 Jun 2022 21:59:27 +0900 Subject: [PATCH 22/48] =?UTF-8?q?BFS,=20=EB=AC=B8=EC=9E=90=EC=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Today_22_06_08/gameMapQueue.java | 52 +++++++++++++ .../src/Today_22_06_08/menuRenewal.java | 73 +++++++++++++++++++ .../src/Today_22_06_08/stringApchuck.java | 56 ++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_06_08/gameMapQueue.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_08/menuRenewal.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_08/stringApchuck.java diff --git a/Basic_Of_Algorithm/src/Today_22_06_08/gameMapQueue.java b/Basic_Of_Algorithm/src/Today_22_06_08/gameMapQueue.java new file mode 100644 index 0000000..e9993bc --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_08/gameMapQueue.java @@ -0,0 +1,52 @@ +package Today_22_06_08; + +import java.util.Queue; +import java.util.LinkedList; + +public class gameMapQueue { + + public static void main(String[] args) { + + int[][]maps = {{1,0,1,1,1},{1,0,1,0,1},{1,0,1,1,1},{1,1,1,0,1},{0,0,0,0,1}}; + + int[][]move = {{0,1},{1,0},{0,-1},{-1,0}}; + + int answer = 0; + + int[][]temp = new int[maps.length][maps.length]; + + temp[0][0] = 1; + + Queue q = new LinkedList<>(); + + q.add(new int[] {0,0}); + + while(!q.isEmpty()) { + + int[]cur = q.poll(); + + int i = cur[0]; + int j = cur[1]; + + for(int d=0;d<4;d++) { + + int newI = move[d][0] + i; + int newJ = move[d][1] + j; + + if(newI<0||newJ<0||maps.length-1 map = new HashMap<>(); + static ArrayList answerList = new ArrayList<>(); + public static void main(String[] args) { + + String []orders = {"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}; + int []course = {2,3,4}; + + for(int i=0;i maxList = new ArrayList<>(map.values()); + int max = Collections.max(maxList); + if(max>1) { + for(String key : map.keySet()) { + if(map.get(key)==max) { + answerList.add(key); + } + } + } + } + + map.clear(); + } + + + String[]answer = new String[answerList.size()]; + + Collections.sort(answerList); + + for(int i=0;i " +result.length()); + + + } + + if(answer==Integer.MAX_VALUE) answer=1; + + System.out.println(answer); + + + + } + static String hitProess(int hit) { + return hit>1 ? String.valueOf(hit) : ""; + } +} From 9c21fdcaf3e78637d66e11eae9b75773f1c2ddb4 Mon Sep 17 00:00:00 2001 From: monsileI Date: Thu, 9 Jun 2022 22:50:24 +0900 Subject: [PATCH 23/48] 06-09 --- .../src/Today_22_06_09/no_1.java | 97 +++++++++++++++++++ .../src/Today_22_06_09/no_2.java | 72 ++++++++++++++ Basic_Of_Algorithm/src/test/bfs.java | 55 ----------- Basic_Of_Algorithm/src/test/dfs.java | 16 --- Basic_Of_Algorithm/src/test/test1.java | 62 ------------ 5 files changed, 169 insertions(+), 133 deletions(-) create mode 100644 Basic_Of_Algorithm/src/Today_22_06_09/no_1.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_09/no_2.java delete mode 100644 Basic_Of_Algorithm/src/test/bfs.java delete mode 100644 Basic_Of_Algorithm/src/test/dfs.java delete mode 100644 Basic_Of_Algorithm/src/test/test1.java diff --git a/Basic_Of_Algorithm/src/Today_22_06_09/no_1.java b/Basic_Of_Algorithm/src/Today_22_06_09/no_1.java new file mode 100644 index 0000000..35d3f24 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_09/no_1.java @@ -0,0 +1,97 @@ +package Today_22_06_09; + +import java.util.ArrayList; +import java.util.Collections; + +public class no_1 { + + static int[]apeach; + static int[]ryan; + static boolean[]visited = new boolean[3]; + static char[]op = {'*','+','-'}; + static int max = 0; + static int N; + static ArrayList answerList = new ArrayList<>(); + + public static void main(String[] args) { + + int[] info = {2,1,1,1,0,0,0,0,0,0,0}; + int n = 5; + + N = n; + apeach = info.clone(); + + ryan = new int[apeach.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 o1[i]-o2[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>max) { + max = diff; + answerList.clear(); + answerList.add(ryan.clone()); + }else if(diff==max) { + answerList.add(ryan.clone()); + } + } + + + return; + } + + + + for(int i=0;i<11;i++) { + ryan[i]++; + dfs(i,count+1); + ryan[i]--; + + } + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_06_09/no_2.java b/Basic_Of_Algorithm/src/Today_22_06_09/no_2.java new file mode 100644 index 0000000..34f9387 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_09/no_2.java @@ -0,0 +1,72 @@ +package Today_22_06_09; + +public class no_2 { + + static char[]member = {'A','C','F','J','M','N','R','T'}; + static int answer = 0; + static boolean[ ] visited; + static String[]d; + + public static void main(String[] args) { + + int n = 2; + + String[]data = {"N~F=0", "R~T>2"}; + + d = data.clone(); + + visited = new boolean[member.length]; + + dfs(""); + + System.out.println(answer); + + } + + static boolean check(String now) { + + for(String str : d) { + + int pos1 = now.indexOf(str.charAt(0)); + int pos2 = now.indexOf(str.charAt(2)); + char op = str.charAt(3); + int idx = str.charAt(4)-'0'; + + if(op=='=') { + if(!(Math.abs(pos1-pos2)==idx+1)) return false; + }else if(op=='>') { + if(!(Math.abs(pos1-pos2)>idx+1)) return false; + }else if(op=='=') { + if(!(Math.abs(pos1-pos2) q = new LinkedList<>(); - - int [][] move = {{0,1},{1,0},{0,-1},{-1,0}}; - - q.add(new int[]{0,0}); - - while(!q.isEmpty()) { - - int [] cur = q.poll(); - - int cI = cur[0]; - int cJ = cur[1]; - - for(int d=0;d<4;d++) { - - int newI = cI + move[d][0]; - int newJ = cJ + move[d][1]; - - - if(newI<0||newJ<0||maps.length-1 q = new LinkedList<>(); - - q.add(new int[] {0,0}); - - int[][]move = {{0,1},{1,0},{0,-1},{-1,0}}; - - while(!q.isEmpty()) { - - int[]cur = q.poll(); - - int i = cur[0]; - int j = cur[1]; - - - - for(int d=0;d<4;d++) { - - int newI = i + move[d][0]; - int newJ = j + move[d][1]; - - - if(newI<0||newJ<0||maps.length-1 Date: Fri, 10 Jun 2022 18:59:22 +0900 Subject: [PATCH 24/48] =?UTF-8?q?=ED=95=9C=EB=AC=B8=EC=A0=9C=20=EB=A7=8C?= =?UTF-8?q?=EC=9D=B4=EB=9D=BC=EB=8F=84=20=E3=85=A0=E3=85=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/programmers_level_2/no_13.java | 54 ++++++++++++++ .../src/programmers_level_2/no_14.java | 70 +++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_13.java create mode 100644 Basic_Of_Algorithm/src/programmers_level_2/no_14.java diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_13.java b/Basic_Of_Algorithm/src/programmers_level_2/no_13.java new file mode 100644 index 0000000..ef45464 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_13.java @@ -0,0 +1,54 @@ +package programmers_level_2; + +import java.util.ArrayList; +import java.util.HashMap; + +public class no_13 { + + + public static void main(String[] args) { + +String [] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"}; + + HashMap map = new HashMap<>(); + ArrayList answerList = new ArrayList<>(); + + 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]; + + map.put(id, nick); + + } + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Change")) continue; + + String nick = map.get(id); + String ans = nick + "님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + } + + + String[]answer = new String[answerList.size()]; + + for(int i = 0 ; i< answerList.size();i++) answer[i] = answerList.get(i); + + for(String str : answer)System.out.println(str); + + + } +} diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_14.java b/Basic_Of_Algorithm/src/programmers_level_2/no_14.java new file mode 100644 index 0000000..a6353ea --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_14.java @@ -0,0 +1,70 @@ +package programmers_level_2; + +public class no_14 { + + public static void main(String[] args) { + + String p = "()))((()"; + + System.out.println(solution(p)); + + } + + static String solution(String p) { + + String answer = change(p); + + + + return answer; + + + } + static String change(String w) { + + if(w.isEmpty())return ""; + + String u = ""; + String v = ""; + + int l = 0; + int r = 0; + int i; + for(i=0;i Date: Wed, 15 Jun 2022 17:26:27 +0900 Subject: [PATCH 25/48] =?UTF-8?q?collatz=EC=97=90=20=EA=B4=80=ED=95=B4?= =?UTF-8?q?=EC=84=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interestingAlgorithm/Collatz_Graph.java | 31 ++++++++++ .../src/interestingAlgorithm/HashMapTest.java | 62 +++++++++++++++++++ .../collatz_conjecture.java | 21 +++++++ 3 files changed, 114 insertions(+) create mode 100644 Basic_Of_Algorithm/src/interestingAlgorithm/Collatz_Graph.java create mode 100644 Basic_Of_Algorithm/src/interestingAlgorithm/HashMapTest.java create mode 100644 Basic_Of_Algorithm/src/interestingAlgorithm/collatz_conjecture.java diff --git a/Basic_Of_Algorithm/src/interestingAlgorithm/Collatz_Graph.java b/Basic_Of_Algorithm/src/interestingAlgorithm/Collatz_Graph.java new file mode 100644 index 0000000..2291b9a --- /dev/null +++ b/Basic_Of_Algorithm/src/interestingAlgorithm/Collatz_Graph.java @@ -0,0 +1,31 @@ +package interestingAlgorithm; + +import java.util.Scanner; + +public class Collatz_Graph { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int n = scan.nextInt(); + + + while(n!=1) { + + if(n%2==0) n /=2; + else n = (n*3) + 1; + + for(int i =0;iuser = new HashMap<>(); + + + for(String str : record) { + + String[]temp = str.split(" "); + + String action =temp[0]; + String id = temp[1]; + + if(action.equals("Leave"))continue; + + user.put(id, temp[2]); + + + } + + ArrayListanswerList = new ArrayList<>(); + + for(String str : record) { + + String[]temp = str.split(" "); + + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Change"))continue; + + String nick = user.get(id); + + String ans = nick +"님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + + } + + + answer = new String[answerList.size()]; + + for(int i=0;i Date: Thu, 16 Jun 2022 21:50:50 +0900 Subject: [PATCH 26/48] =?UTF-8?q?=EB=B8=8C=EB=A3=A8=ED=8A=B8=ED=8F=AC?= =?UTF-8?q?=EC=8A=A4=20=EA=B8=B0=EB=B3=B8(=EC=83=89=EC=95=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bruthForce_backjoon.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Basic_Of_Algorithm/src/interestingAlgorithm/bruthForce_backjoon.java diff --git a/Basic_Of_Algorithm/src/interestingAlgorithm/bruthForce_backjoon.java b/Basic_Of_Algorithm/src/interestingAlgorithm/bruthForce_backjoon.java new file mode 100644 index 0000000..a4bb9ee --- /dev/null +++ b/Basic_Of_Algorithm/src/interestingAlgorithm/bruthForce_backjoon.java @@ -0,0 +1,69 @@ +package interestingAlgorithm; + + +public class bruthForce_backjoon { + + static int normal = 0; + static boolean visited[][]; + + public static void main(String[] args) { + + String []temp = {"RRRBB", + "GGBBB", + "BBBRR", + "BBRRR", + "RRRRR"}; + + char[][]map = new char[temp.length][temp[0].length()]; + + + for(int i=0;i Date: Fri, 17 Jun 2022 22:32:22 +0900 Subject: [PATCH 27/48] =?UTF-8?q?=EB=82=B4=EC=9D=BC=20=EC=8B=9C=ED=97=98?= =?UTF-8?q?=20=E3=85=A0=E3=85=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Basic_Of_Algorithm/src/test/color.java | 81 +++++++++++++++++++++++ Basic_Of_Algorithm/src/test/dfs.java | 57 ++++++++++++++++ Basic_Of_Algorithm/src/test/network.java | 38 +++++++++++ Basic_Of_Algorithm/src/test/network2.java | 39 +++++++++++ 4 files changed, 215 insertions(+) create mode 100644 Basic_Of_Algorithm/src/test/color.java create mode 100644 Basic_Of_Algorithm/src/test/dfs.java create mode 100644 Basic_Of_Algorithm/src/test/network.java create mode 100644 Basic_Of_Algorithm/src/test/network2.java diff --git a/Basic_Of_Algorithm/src/test/color.java b/Basic_Of_Algorithm/src/test/color.java new file mode 100644 index 0000000..52513e6 --- /dev/null +++ b/Basic_Of_Algorithm/src/test/color.java @@ -0,0 +1,81 @@ +package test; + +public class color { + + public static void main(String[] args) { + + String[]temp = {"RRRBB", + "GGBBB", + "BBBRR", + "BBRRR", + "RRRRR"}; + + char[][]map = new char[temp.length][temp[0].length()]; + + + for(int i=0;i Date: Tue, 21 Jun 2022 21:59:10 +0900 Subject: [PATCH 28/48] ddd --- Basic_Of_Algorithm/src/test/ddd.java | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Basic_Of_Algorithm/src/test/ddd.java diff --git a/Basic_Of_Algorithm/src/test/ddd.java b/Basic_Of_Algorithm/src/test/ddd.java new file mode 100644 index 0000000..7888a06 --- /dev/null +++ b/Basic_Of_Algorithm/src/test/ddd.java @@ -0,0 +1,39 @@ +package test; + +public class ddd { + + public static void main(String[] args) { + + + int n = 3; + + int[][]computers = {{1,1,0},{1,1,0},{0,0,1}}; + + int answer = 0; + + boolean[]visited = new boolean[computers.length]; + + for(int i=0;i Date: Wed, 22 Jun 2022 17:42:20 +0900 Subject: [PATCH 29/48] =?UTF-8?q?=EC=98=A4=EB=9E=9C=EB=A7=8C=EC=97=90=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98=EB=A8=B8=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Basic_Of_Algorithm/src/test/bfs.java | 50 +++++++++++ Basic_Of_Algorithm/src/test/binarySearch.java | 83 +++++++++++++++++++ Basic_Of_Algorithm/src/test/dungeons.java | 35 ++++++++ 3 files changed, 168 insertions(+) create mode 100644 Basic_Of_Algorithm/src/test/bfs.java create mode 100644 Basic_Of_Algorithm/src/test/binarySearch.java create mode 100644 Basic_Of_Algorithm/src/test/dungeons.java diff --git a/Basic_Of_Algorithm/src/test/bfs.java b/Basic_Of_Algorithm/src/test/bfs.java new file mode 100644 index 0000000..9273400 --- /dev/null +++ b/Basic_Of_Algorithm/src/test/bfs.java @@ -0,0 +1,50 @@ +package test; + +import java.util.Queue; +import java.util.LinkedList; + +public class bfs { + + public static void main(String[] args) { + + int[][]maps = {{1,0,1,1,1},{1,0,1,0,1},{1,0,1,1,1},{1,1,1,0,1},{0,0,0,0,1}}; + int answer = 0; + + Queue q= new LinkedList<>(); + + q.add(new int[] {0,0}); + + int[][]temp = new int[maps.length][maps[0].length]; + + temp[0][0] = 1; + + int[][]move = {{1,0},{0,1},{-1,0},{0,-1}}; + + while(!q.isEmpty()) { + int []cur = q.poll(); + + int i = cur[0]; + int j = cur[1]; + + for(int d=0;d<4;d++) { + int newI = i + move[d][0]; + int newJ = j + move[d][1]; + + if(newI<0||newJ<0||maps.length-1>infoMap = new HashMap<>(); + + public static void main(String[] args) { + + String[]info = {"java backend junior pizza 150","python frontend senior chicken 210","python frontend senior chicken 150","cpp backend senior pizza 260","java backend junior chicken 80","python backend senior chicken 50"}; + String[]query = {"java and backend and junior and pizza 100","python and frontend and senior and chicken 200","cpp and - and senior and pizza 250","- and backend and senior and - 150","- and - and - and chicken 100","- and - and - and - 150"}; + + int[]answer = new int[query.length]; + + + + for(String str : info) { + + String[]temp = str.split(" "); + dfs(temp,0,""); + + } + + for(int i=0;i list = new ArrayList<>(infoMap.get(temp[0])); + + Collections.sort(list); + + int start = 0; + int end = list.size()-1; + int score = Integer.parseInt(temp[1]); + + + + while(start<=end) { + + int mid = (start+end)/2; + + if(score>list.get(mid)) start = mid+1; + else end = mid-1; + + } + + + return list.size()-start; + } + + static void dfs(String[]temp,int count,String now) { + + if(count==4) { + if(!infoMap.containsKey(now)) { + infoMap.put(now, new ArrayList()); + } + infoMap.get(now).add(Integer.parseInt(temp[4])); + return; + } + + dfs(temp,count+1,now+temp[count]); + dfs(temp,count+1,now+"-"); + + + + } + +} diff --git a/Basic_Of_Algorithm/src/test/dungeons.java b/Basic_Of_Algorithm/src/test/dungeons.java new file mode 100644 index 0000000..e46061e --- /dev/null +++ b/Basic_Of_Algorithm/src/test/dungeons.java @@ -0,0 +1,35 @@ +package test; + +public class dungeons { + + static int answer = 0; + + public static void main(String[] args) { + + int k = 80; + int [][] dungeons = {{80,20},{50,40},{30,10}}; + boolean[] visited = new boolean[dungeons.length]; + + dfs(visited,dungeons,k,0); + + System.out.println(answer); + + } + + static void dfs(boolean[]visited,int[][]dungeons,int k,int count) { + + + for(int i=0;i Date: Thu, 23 Jun 2022 20:26:34 +0900 Subject: [PATCH 30/48] =?UTF-8?q?=EB=8B=AC=ED=8C=BD=EC=9D=B4=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20-=20=EB=B0=B1=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Basic_Of_Algorithm/src/test/snail.java | 109 +++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Basic_Of_Algorithm/src/test/snail.java diff --git a/Basic_Of_Algorithm/src/test/snail.java b/Basic_Of_Algorithm/src/test/snail.java new file mode 100644 index 0000000..17833e0 --- /dev/null +++ b/Basic_Of_Algorithm/src/test/snail.java @@ -0,0 +1,109 @@ +package test; + +import java.io.*; + +public class snail { + + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + int t = Integer.parseInt(br.readLine()); + solve1(n,t); // 바깥쪽에서 안쪽 + solve2(n,t); // 안쪽에서 바깥쪽 + + } + + // 바깥쪽에서 안쪽으로 돌기 + static void solve1(int n, int t) { + int[][] map = new int[n][n]; + int value = n*n; + int x=0,y=0; + int time=0; + int limit =n; + while(value>0) { + x=time; + for(int i=y; i=time; i--) { + map[i][x] = value--; + } + + y=time; + for(int i=x-1; i>time; i--) { + map[y][i] = value--; + } + time++; + limit--; + y=time; + } + + StringBuilder sb = new StringBuilder(); + int tx=0, ty=0; + for(int i=0; i Date: Fri, 24 Jun 2022 17:43:30 +0900 Subject: [PATCH 31/48] combination --- .../src/test/combination_Algorithm.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Basic_Of_Algorithm/src/test/combination_Algorithm.java diff --git a/Basic_Of_Algorithm/src/test/combination_Algorithm.java b/Basic_Of_Algorithm/src/test/combination_Algorithm.java new file mode 100644 index 0000000..59ce02d --- /dev/null +++ b/Basic_Of_Algorithm/src/test/combination_Algorithm.java @@ -0,0 +1,78 @@ +package test; + +public class combination_Algorithm { + +public static void main(String[] args) { + + int [] arr = {1,2,3}; + + boolean[]visited = new boolean[arr.length]; + + combi(arr,visited); + + dfs(arr,visited,""); + + + } + + + + static void dfs(int[]arr,boolean[]visited,String now) { + + System.out.println(now); + + if(now.length()==arr.length) return; + + for(int i=0;i Date: Tue, 28 Jun 2022 19:39:38 +0900 Subject: [PATCH 32/48] bfs && dfs --- .../src/Today_22_06_28/bfs.java | 51 ++++++++++++++ .../src/Today_22_06_28/dfs.java | 68 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 Basic_Of_Algorithm/src/Today_22_06_28/bfs.java create mode 100644 Basic_Of_Algorithm/src/Today_22_06_28/dfs.java diff --git a/Basic_Of_Algorithm/src/Today_22_06_28/bfs.java b/Basic_Of_Algorithm/src/Today_22_06_28/bfs.java new file mode 100644 index 0000000..734d805 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_28/bfs.java @@ -0,0 +1,51 @@ +package Today_22_06_28; + +import java.util.Queue; +import java.util.LinkedList; + +public class bfs { + + public static void main(String[] args) { + + int[][]maps = {{1,0,1,1,1},{1,0,1,0,1},{1,0,1,1,1},{1,1,1,0,1},{0,0,0,0,1}}; + + int [][] temp = new int[maps.length][maps[0].length]; + + int answer; + + temp[0][0] = 1; + + Queue bfs = new LinkedList<>(); + + bfs.add(new int[] {0,0}); + + int [][]move = {{1,0},{0,1},{-1,0},{0,-1}}; + + while(!bfs.isEmpty()) { + + int[]cur = bfs.poll(); + + int i = cur[0]; + int j = cur[1]; + + for(int d=0;d<4;d++) { + int newI = i + move[d][0]; + int newJ = j + move[d][1]; + + if(newI<0||newJ<0||maps.length-12"}; + + dataSample = data.clone(); + + dfs(""); + + System.out.println(answer); + + } + static boolean check(String now) { + + for(String d : dataSample) { + + int pos1 = now.indexOf(d.charAt(0)); + int pos2 = now.indexOf(d.charAt(2)); + char op = d.charAt(3); + int idx = (d.charAt(4) - '0') + 1; + + if(op=='=') { + if(!(Math.abs(pos1-pos2)==idx)) return false; + }else if(op=='>') { + if(!(Math.abs(pos1-pos2)>idx)) return false; + }else if(op=='<') { + if(!(Math.abs(pos1-pos2) Date: Wed, 29 Jun 2022 21:12:46 +0900 Subject: [PATCH 33/48] =?UTF-8?q?=EC=98=A4=ED=94=88=EC=B1=84=ED=8C=85?= =?UTF-8?q?=EB=B0=A9=20(=20=EB=A7=B5=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Basic_Of_Algorithm/src/test/openChatting.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Basic_Of_Algorithm/src/test/openChatting.java diff --git a/Basic_Of_Algorithm/src/test/openChatting.java b/Basic_Of_Algorithm/src/test/openChatting.java new file mode 100644 index 0000000..a68d28c --- /dev/null +++ b/Basic_Of_Algorithm/src/test/openChatting.java @@ -0,0 +1,52 @@ +package test; + +import java.util.HashMap; +import java.util.ArrayList; + +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"}; + + HashMap map = new HashMap<>(); + + ArrayList answerList = new ArrayList<>(); + + 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]; + + map.put(id, nick); + + } + + + for(String str : record) { + + String []temp = str.split(" "); + + String action = temp[0]; + String id = temp[1]; + if(action.contains("Change"))continue; + String nick = map.get(id); + + String ans = nick+"님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + } + + String[]answer = new String[answerList.size()]; + + for(int i=0;i Date: Thu, 30 Jun 2022 20:14:59 +0900 Subject: [PATCH 34/48] =?UTF-8?q?=EC=A3=BC=EC=B0=A8=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Basic_Of_Algorithm/src/test/parking.java | 76 ++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Basic_Of_Algorithm/src/test/parking.java diff --git a/Basic_Of_Algorithm/src/test/parking.java b/Basic_Of_Algorithm/src/test/parking.java new file mode 100644 index 0000000..9aec947 --- /dev/null +++ b/Basic_Of_Algorithm/src/test/parking.java @@ -0,0 +1,76 @@ +package test; + +import java.util.*; + +public class parking { + + public static void main(String[] args) { + + int[]fees= {180, 5000, 10, 600}; + String[]records = {"05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT"}; + + HashMap map = new HashMap<>(); + TreeMap tree = new TreeMap<>(); + + for(String s : records) { + + String []temp = s.split(" "); + int time = timeChange(temp[0]); + String num = temp[1]; + String action = temp[2]; + + if(action.equals("IN")) { + if(!tree.containsKey(num)) tree.put(num, 0); + map.put(num, time); + } + else { + + tree.put(num, tree.get(num) + (time - map.get(num))); + map.remove(num); + } + } + + if(!map.isEmpty()) { + for(String key : map.keySet()) { + tree.put(key, tree.get(key) + (23*60+59) - map.get(key)); + + } + } + + ArrayListanswerList = new ArrayList<>(); + + for(String key : tree.keySet()) { + + double time = tree.get(key); + + if(time<=fees[0]) { + answerList.add(fees[1]); + }else { + time = time - fees[0]; + double cal = time/fees[2]; + int extraTime = (int) Math.ceil(cal); + int fee = (extraTime * fees[3]) + fees[1]; + answerList.add(fee); + } + } + + int[]answer = new int[answerList.size()]; + for(int i=0;i Date: Fri, 1 Jul 2022 19:35:33 +0900 Subject: [PATCH 35/48] =?UTF-8?q?dfs=20=EC=9D=91=EC=9A=A9=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Basic_Of_Algorithm/src/test/dungeon.java | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Basic_Of_Algorithm/src/test/dungeon.java diff --git a/Basic_Of_Algorithm/src/test/dungeon.java b/Basic_Of_Algorithm/src/test/dungeon.java new file mode 100644 index 0000000..e83400f --- /dev/null +++ b/Basic_Of_Algorithm/src/test/dungeon.java @@ -0,0 +1,42 @@ +package test; + +public class dungeon { + + static int answer = 0; + + public static void main(String[] args) { + + int k = 80; + int[][]dungeons = {{80,20},{50,40},{30,10}}; + boolean[]visited = new boolean[dungeons.length]; + + dfs(dungeons,k,visited,0); + + System.out.println(answer); + + + } + + static void dfs(int[][]dungeons,int k,boolean[]visited,int count) { + + + + for(int i=0;i Date: Mon, 4 Jul 2022 20:55:09 +0900 Subject: [PATCH 36/48] =?UTF-8?q?=EA=B7=80=EB=82=A9=EB=B2=95=20=EC=A6=9D?= =?UTF-8?q?=EB=AA=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\352\267\200\353\202\251\353\262\225.java" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "Basic_Of_Algorithm/src/test/\352\267\200\353\202\251\353\262\225.java" diff --git "a/Basic_Of_Algorithm/src/test/\352\267\200\353\202\251\353\262\225.java" "b/Basic_Of_Algorithm/src/test/\352\267\200\353\202\251\353\262\225.java" new file mode 100644 index 0000000..ae7f8f7 --- /dev/null +++ "b/Basic_Of_Algorithm/src/test/\352\267\200\353\202\251\353\262\225.java" @@ -0,0 +1,34 @@ +package test; + +import java.util.Scanner;; + +public class 귀납법 { + + public static void main(String[] args) { + + + Scanner scan = new Scanner(System.in); + + int n = scan.nextInt(); + + int m = test(n); + + int l = 0; + + for(int i=n;i>-1;i--) { + l += i; + } + + if(l==m) System.out.println("이게 귀납법"); + + System.out.println(l); + System.out.println(m); + } + + static int test(int n) { + + if(n==0) return n; + return n+test(n-1); + + } +} From fed2a7a5d40ed333630ad7fcc371a4ed3b479476 Mon Sep 17 00:00:00 2001 From: monsileI Date: Tue, 5 Jul 2022 23:02:41 +0900 Subject: [PATCH 37/48] dfs --- .../src/interestingAlgorithm/dfs.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Basic_Of_Algorithm/src/interestingAlgorithm/dfs.java diff --git a/Basic_Of_Algorithm/src/interestingAlgorithm/dfs.java b/Basic_Of_Algorithm/src/interestingAlgorithm/dfs.java new file mode 100644 index 0000000..096c5f6 --- /dev/null +++ b/Basic_Of_Algorithm/src/interestingAlgorithm/dfs.java @@ -0,0 +1,38 @@ +package interestingAlgorithm; + +public class dfs { + + public static void main(String[] args) { + + int[]arr = {1,2,3}; + + boolean[]visited = new boolean[arr.length]; + + dfs(arr,0,"",visited); + + + } + + static void dfs(int[]arr,int count,String now,boolean[]visited) { + + if(count==arr.length) { + System.out.println(now); + return; + } + + for(int i=0;i Date: Wed, 6 Jul 2022 22:56:26 +0900 Subject: [PATCH 38/48] =?UTF-8?q?=EB=82=B4=EC=9D=BC=20=EB=B6=84=EB=B0=98?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=E3=85=A0=E3=85=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/sw_java_im/no_1244.java | 12 ++++++ .../src/sw_java_im/no_2527.java | 41 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Basic_Of_Algorithm/src/sw_java_im/no_1244.java create mode 100644 Basic_Of_Algorithm/src/sw_java_im/no_2527.java diff --git a/Basic_Of_Algorithm/src/sw_java_im/no_1244.java b/Basic_Of_Algorithm/src/sw_java_im/no_1244.java new file mode 100644 index 0000000..4e344d7 --- /dev/null +++ b/Basic_Of_Algorithm/src/sw_java_im/no_1244.java @@ -0,0 +1,12 @@ +package sw_java_im; + +public class no_1244 { + + public static void main(String[] args) { + + + + + } + +} diff --git a/Basic_Of_Algorithm/src/sw_java_im/no_2527.java b/Basic_Of_Algorithm/src/sw_java_im/no_2527.java new file mode 100644 index 0000000..ee6714c --- /dev/null +++ b/Basic_Of_Algorithm/src/sw_java_im/no_2527.java @@ -0,0 +1,41 @@ +package sw_java_im; + +import java.util.Scanner; + +public class no_2527 { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + for(int i=0;i<4;i++) { + + int x1 = scan.nextInt(); + int y1 = scan.nextInt(); + int x2 = scan.nextInt(); + int y2 = scan.nextInt(); + int x3 = scan.nextInt(); + int y3 = scan.nextInt(); + int x4 = scan.nextInt(); + int y4 = scan.nextInt(); + + //점 + if((x2 == x3 && y2 == y3) || (x1 == x4 && y1 == y4) + || (x2 == x3 && y1 == y4) || (x1 == x4 && y2 == y3)) { + System.out.println("c"); + //선분 + }else if((x2==x3 && y2 != y3) || (x1==x4 && y1 != y4) || + (x2==x3 && y1 != y4) || (x2!=x3 && y1 == y4)){ + System.out.println("b"); + //겹치지 않을 경구 + }else if(x2 < x3 || x4 < x1 || y2 < y3 || y4 < y1) System.out.println("d"); + + else System.out.println("a"); + + + + } + + } + +} From c3a3f9f1acc8fcd12b44804458dcf97dee8f21cd Mon Sep 17 00:00:00 2001 From: monsileI Date: Thu, 7 Jul 2022 19:25:51 +0900 Subject: [PATCH 39/48] =?UTF-8?q?=EC=BD=94=ED=85=8C=20=EB=84=88=EB=AC=B4?= =?UTF-8?q?=20=EC=96=B4=EB=A0=A4=EC=9B=8C=20=E3=85=A0=E3=85=A0=20=EC=96=B8?= =?UTF-8?q?=EC=A0=9C=20=EB=8A=98=EC=96=B4..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/sw_java_im/no_1244.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/Basic_Of_Algorithm/src/sw_java_im/no_1244.java b/Basic_Of_Algorithm/src/sw_java_im/no_1244.java index 4e344d7..8d5fbb4 100644 --- a/Basic_Of_Algorithm/src/sw_java_im/no_1244.java +++ b/Basic_Of_Algorithm/src/sw_java_im/no_1244.java @@ -1,12 +1,88 @@ package sw_java_im; +import java.util.Scanner; + public class no_1244 { public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int count = sc.nextInt(); + + int [] arr = new int[count+1]; + + arr[0] = 0; + + for(int i=1;i=arr.length) break; + + + } + + + }else { + + if(arr[loc]==0) arr[loc] = 1; + else arr[loc] = 0; + + int left = loc-1; + int right = loc+1; + + while(true) { + + if(left<1 || arr.length Date: Fri, 8 Jul 2022 20:12:54 +0900 Subject: [PATCH 40/48] dfs target --- Basic_Of_Algorithm/src/sw_java_im/no_3.java | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Basic_Of_Algorithm/src/sw_java_im/no_3.java diff --git a/Basic_Of_Algorithm/src/sw_java_im/no_3.java b/Basic_Of_Algorithm/src/sw_java_im/no_3.java new file mode 100644 index 0000000..7ff28f3 --- /dev/null +++ b/Basic_Of_Algorithm/src/sw_java_im/no_3.java @@ -0,0 +1,35 @@ +package sw_java_im; + +public class no_3 { + + static int answer = 0 ; + static int t; + public static void main(String[] args) { + + + int [] arr = {1,1,1,1,1}; + int target = 3; + t = target; + + dfs(arr,0,0); + + System.out.println(answer); + } + + static void dfs(int[]arr,int now,int count) { + + if(count==arr.length) { + if(now==t) answer++; + + return; + } + + dfs(arr,now+arr[count],count+1); + dfs(arr,now-arr[count],count+1); + + + + + } + +} From 2f053e5f1e311aec8727a3b028a1517185568df5 Mon Sep 17 00:00:00 2001 From: monsileI Date: Sat, 9 Jul 2022 21:22:20 +0900 Subject: [PATCH 41/48] =?UTF-8?q?ssafy=20=EC=82=AC=EC=A0=84=20=ED=95=99?= =?UTF-8?q?=EC=8A=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ssafy_avanced_study/no_1249.java | 82 +++++++++++++ .../src/ssafy_avanced_study/no_1936.java | 37 ++++++ .../src/ssafy_avanced_study/no_1946.java | 60 ++++++++++ .../src/ssafy_avanced_study/no_1959.java | 71 ++++++++++++ .../src/ssafy_avanced_study/no_1961.java | 83 ++++++++++++++ .../src/ssafy_avanced_study/no_1974.java | 68 +++++++++++ .../src/ssafy_avanced_study/no_1979.java | 108 ++++++++++++++++++ .../src/ssafy_avanced_study/no_2001.java | 50 ++++++++ 8 files changed, 559 insertions(+) create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1936.java create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1946.java create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1959.java create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1961.java create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1974.java create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1979.java create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_2001.java diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java new file mode 100644 index 0000000..40bf1b7 --- /dev/null +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java @@ -0,0 +1,82 @@ +package ssafy_avanced_study; + +import java.util.Scanner; +import java.util.Queue; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.LinkedList; + +public class no_1249 { + + static int answer = Integer.MAX_VALUE; + + public static void main(String[] args) throws Exception { + + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T; + T=Integer.parseInt(br.readLine()); + + for(int test_case = 1; test_case <= T; test_case++){ + + int size =Integer.parseInt(br.readLine()); + + int[][]map = new int[size][size]; + + for(int i=0;isize-2 && j>size-2) { + + answer = Math.min(answer, now); + return; + } + + for(int d=0;d<4;d++) { + + int newI = i + move[d][0]; + int newJ = j + move[d][1]; + + if(newI<0||newJ<0||size-13) { + count = Integer.parseInt(""+str.charAt(2)+str.charAt(3)); + }else if(str.charAt(2)=='2' && str.length()>3) { + count = Integer.parseInt(""+str.charAt(2)+str.charAt(3)); + } + else count = Integer.parseInt(String.valueOf(str.charAt(2))); + + for(int j=0;j-1;i--) { + map1[j][size-i-1] = map[i][j]; + } + + } + + int[][]map2 = new int[size][size]; + + + for(int i=size-1;i>-1;i--) { + for(int j=size-1;j>-1;j--) { + map2[size-i-1][size-j-1] = map[i][j]; + } + + } + + int[][]map3 = new int[size][size]; + + for(int j=size-1;j>-1;j--) { + for(int i=0;i1 || arr2[map[i][j]-1]>1) { + flag = false; + break outerLoop; + } + + + } + + } + outerLoop: + for(int l=0;l<3;l++) { + + int[]arr = new int[9]; + + for(int i=0;i<3;i++) { + for(int j=0;j<3;j++) { + arr[map[i+(l*3)][j+(l*3)]-1]++; + if(arr[map[i][j]-1]>1) { + flag = false; + break outerLoop; + } + + } + } + } + + + if(!flag) answer += 0 ; + else answer += 1; + + System.out.println(answer); + + + + } + } +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1979.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1979.java new file mode 100644 index 0000000..bf7f756 --- /dev/null +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1979.java @@ -0,0 +1,108 @@ +package ssafy_avanced_study; + +import java.util.Scanner; +import java.util.Stack; + +public class no_1979 { + + public static void main(String[] args) { + + + Scanner sc = new Scanner(System.in); + int T; + T=sc.nextInt(); + + for(int test_case = 1; test_case <= T; test_case++){ + + String answer = "#"+test_case+" "; + + int size = sc.nextInt(); + int len = sc.nextInt(); + int ans = 0; + + int [][]map = new int[size][size]; + + for(int i=0;i stack = new Stack<>(); + for(int j=0;j stack = new Stack<>(); + for(int i=0;i Date: Mon, 11 Jul 2022 19:51:52 +0900 Subject: [PATCH 42/48] =?UTF-8?q?=ED=95=B4=EA=B2=B0=EC=9D=B4=20=EC=95=88?= =?UTF-8?q?=EB=90=98=EB=84=A4=20..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ssafy_avanced_study/no_1226.java | 96 +++++++++++++++++++ .../src/ssafy_avanced_study/no_1249.java | 85 ++++++++-------- 2 files changed, 140 insertions(+), 41 deletions(-) create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java new file mode 100644 index 0000000..69eace5 --- /dev/null +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java @@ -0,0 +1,96 @@ +package ssafy_avanced_study; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Queue; +import java.util.LinkedList; + +public class no_1226 { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T; + T= Integer.parseInt(br.readLine()); + /* + 여러 개의 테스트 케이스가 주어지므로, 각각을 처리합니다. + */ + + for(int test_case = 1; test_case <= T; test_case++) + { + + int[][]map = new int[16][16]; + + Queue q = new LinkedList<>(); + + q.add(new int[] {0,0}); + + for(int i=0;i<16;i++) { + String str =br.readLine(); + for(int j=0;j<16;j++) { + map[i][j] = Integer.parseInt(""+str.charAt(j)); + } + } + + int[][]temp = new int[16][16]; + temp[0][0] = 0; + int [][] move = {{1,0},{0,1},{-1,0},{0,-1}}; + + int answer = Integer.MAX_VALUE; + int answerI = 0; + int answerJ = 0; + + for(int i=0;i<16;i++) { + for(int j=0;j<16;j++) { + if(map[i][j]==2) { + temp[i][j] = 0; + q.add(new int[] {i,j}); + }else if(map[i][j]==3) { + answerI = i; + answerJ = j; + } + + } + } + + System.out.println(q.poll()[0]); + System.out.println(q.poll()[1]); + + while(!q.isEmpty()) { + + int [] cur = q.poll(); + int i = cur[0]; + int j = cur[1]; + + for(int d=0;d<4;d++) { + + int newI = i + move[d][0]; + int newJ = j + move[d][1]; + + + if(newI<0||newJ<0||15 q = new LinkedList<>(); + + q.add(new int[] {0,0}); + for(int i=0;isize-2 && j>size-2) { + int answer = Integer.MAX_VALUE; - answer = Math.min(answer, now); - return; - } - - for(int d=0;d<4;d++) { - - int newI = i + move[d][0]; - int newJ = j + move[d][1]; + while(!q.isEmpty()) { + + int [] cur = q.poll(); + int i = cur[0]; + int j = cur[1]; + + for(int d=0;d<4;d++) { + + int newI = i + move[d][0]; + int newJ = j + move[d][1]; + + + if(newI<0||newJ<0||size-1 Date: Tue, 12 Jul 2022 21:23:43 +0900 Subject: [PATCH 43/48] =?UTF-8?q?=EC=9D=B4=EA=B2=8C=20=EB=8C=80=EC=B2=B4?= =?UTF-8?q?=20=EC=99=9C=20=EC=95=88=EB=90=98=EB=8A=94=EA=B2=A8=20=E3=85=A0?= =?UTF-8?q?=E3=85=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ssafy_avanced_study/no_1226.java | 89 +++++++++---------- .../src/ssafy_avanced_study/no_1247.java | 23 +++++ .../src/ssafy_avanced_study/no_1249.java | 71 +++++++-------- 3 files changed, 99 insertions(+), 84 deletions(-) create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1247.java diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java index 69eace5..1874fc5 100644 --- a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java @@ -7,6 +7,9 @@ public class no_1226 { + static int answer = 0; + static int [][] move = {{1,0},{0,1},{-1,0},{0,-1}}; + public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -25,72 +28,60 @@ public static void main(String[] args) throws Exception { q.add(new int[] {0,0}); + int []start = new int[2]; + int []end = new int[2]; + for(int i=0;i<16;i++) { String str =br.readLine(); for(int j=0;j<16;j++) { map[i][j] = Integer.parseInt(""+str.charAt(j)); + if(map[i][j]==2) { + start[0] = i; + start[1] = j; + }else if(map[i][j]==3) { + end[0] = i; + end[1] = j; + } } } + + int[][]temp = new int[16][16]; - temp[0][0] = 0; - int [][] move = {{1,0},{0,1},{-1,0},{0,-1}}; + temp[start[0]][start[1]] = 0; - int answer = Integer.MAX_VALUE; - int answerI = 0; - int answerJ = 0; - for(int i=0;i<16;i++) { - for(int j=0;j<16;j++) { - if(map[i][j]==2) { - temp[i][j] = 0; - q.add(new int[] {i,j}); - }else if(map[i][j]==3) { - answerI = i; - answerJ = j; - } - - } - } + dfs(start[0],start[1],temp,end,map); - System.out.println(q.poll()[0]); - System.out.println(q.poll()[1]); - while(!q.isEmpty()) { - - int [] cur = q.poll(); - int i = cur[0]; - int j = cur[1]; - - for(int d=0;d<4;d++) { - - int newI = i + move[d][0]; - int newJ = j + move[d][1]; - - - if(newI<0||newJ<0||15=answer) return; + + int [][] move = {{1,0},{0,1},{-1,0},{0,-1}}; + + + if(i==size-1 && j ==size-1) { + answer = Math.min(answer, temp[size-1][size-1]); + return; + } + + for(int d=0;d<4;d++) { + + int newI = i + move[d][0]; + int newJ = j + move[d][1]; + + if(newI<0||newJ<0||size-1 Date: Tue, 19 Jul 2022 21:56:29 +0900 Subject: [PATCH 44/48] =?UTF-8?q?array=20=EB=B3=B5=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/interestingAlgorithm/arrTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Basic_Of_Algorithm/src/interestingAlgorithm/arrTest.java diff --git a/Basic_Of_Algorithm/src/interestingAlgorithm/arrTest.java b/Basic_Of_Algorithm/src/interestingAlgorithm/arrTest.java new file mode 100644 index 0000000..1dcc3b4 --- /dev/null +++ b/Basic_Of_Algorithm/src/interestingAlgorithm/arrTest.java @@ -0,0 +1,25 @@ +package interestingAlgorithm; + +import java.util.Arrays; + +public class arrTest { + + public static void main(String[] args) { + + + int[]arr = {1,2,3,4,5}; + + int[]scores; + + scores = arr; + + scores[0] = 1320; + + System.out.println(Arrays.toString(arr)); + System.out.println(Arrays.toString(scores)); + + + //주소값을 복사하는 shallow copy는 copy한 영역을 조정해도 원래값도 바뀜 ㅠ + } + +} From 07ca1d827404a5fba8609d2236f560ec0f9e70a7 Mon Sep 17 00:00:00 2001 From: monsileI Date: Wed, 20 Jul 2022 23:44:10 +0900 Subject: [PATCH 45/48] yes test --- .../src/interestingAlgorithm/interesting.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Basic_Of_Algorithm/src/interestingAlgorithm/interesting.java diff --git a/Basic_Of_Algorithm/src/interestingAlgorithm/interesting.java b/Basic_Of_Algorithm/src/interestingAlgorithm/interesting.java new file mode 100644 index 0000000..56c5d1f --- /dev/null +++ b/Basic_Of_Algorithm/src/interestingAlgorithm/interesting.java @@ -0,0 +1,10 @@ +package interestingAlgorithm; + +public class interesting { + + public static void main(String[] args) { + + System.out.println("yes"); + } + +} From c8f0b0b357ae13f562bec35998b2c2f9dc13af69 Mon Sep 17 00:00:00 2001 From: monsileI Date: Sat, 30 Jul 2022 15:38:41 +0900 Subject: [PATCH 46/48] =?UTF-8?q?bfs=20=EC=95=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=A6=98=20=EA=B0=80=EC=A7=80=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ssafy_avanced_study/no_1248.java | 80 ++++++++++++++++++ .../src/ssafy_avanced_study/no_1249.java | 82 +++++++++---------- 2 files changed, 118 insertions(+), 44 deletions(-) create mode 100644 Basic_Of_Algorithm/src/ssafy_avanced_study/no_1248.java diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1248.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1248.java new file mode 100644 index 0000000..9ce4e96 --- /dev/null +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1248.java @@ -0,0 +1,80 @@ +package ssafy_avanced_study; + + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Queue; +import java.util.LinkedList; + +public class no_1248 { + + + + + public static void main(String[] args) throws Exception { + + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T; + T=Integer.parseInt(br.readLine()); + + for(int test_case = 1; test_case <= T; test_case++){ + + int size =Integer.parseInt(br.readLine()); + + int[][]map = new int[size][size]; + + int answer = Integer.MAX_VALUE; + + + for(int i=0;i q = new LinkedList<>(); + + int[][]mov = {{1,0},{0,1},{-1,0},{0,-1}}; + int[][]temp = new int[size][size]; + boolean[][]visited = new boolean[size][size]; + q.add(new int[] {0,0}); + + while(!q.isEmpty()) { + + int []c = q.poll(); + int i = c[0]; + int j = c[1]; + + if(i==size-1 && j==size-1) { + answer = Math.min(answer, temp[i][j]); + continue; + } + if(answer<=temp[i][j]) continue; + + for(int d=0;d<4;d++) { + int ni = i + mov[d][0]; + int nj = j + mov[d][1]; + + if(ni<0 || nj<0|| size-1 temp[i][j] + map[ni][nj]) { + visited[ni][nj] = true; + temp[ni][nj] = temp[i][j] + map[ni][nj]; + q.add(new int[] {ni,nj}); + } + + } + + } + + System.out.println("#"+test_case+" "+answer); + + + + } + + } + +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java index 16557c5..6882c78 100644 --- a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java @@ -8,7 +8,7 @@ public class no_1249 { - static int answer = Integer.MAX_VALUE; + public static void main(String[] args) throws Exception { @@ -24,63 +24,57 @@ public static void main(String[] args) throws Exception { int[][]map = new int[size][size]; - Queue q = new LinkedList<>(); - - q.add(new int[] {0,0}); + int answer = Integer.MAX_VALUE; + for(int i=0;i q = new LinkedList<>(); + int[][]mov = {{1,0},{0,1},{-1,0},{0,-1}}; int[][]temp = new int[size][size]; - temp[0][0] = 0; - - - - - dfs(0,0,temp,map,size); - - System.out.println(answer); - - } - - - } - static void dfs(int i,int j,int[][]temp,int[][]map,int size) { - - - if(map[i][j]>=answer) return; - - int [][] move = {{1,0},{0,1},{-1,0},{0,-1}}; - - - if(i==size-1 && j ==size-1) { - answer = Math.min(answer, temp[size-1][size-1]); - return; - } - - for(int d=0;d<4;d++) { - - int newI = i + move[d][0]; - int newJ = j + move[d][1]; + boolean[][]visited = new boolean[size][size]; + q.add(new int[] {0,0}); - if(newI<0||newJ<0||size-1 temp[i][j] + map[ni][nj]) { + visited[ni][nj] = true; + temp[ni][nj] = temp[i][j] + map[ni][nj]; + q.add(new int[] {ni,nj}); + } + + } + + } + System.out.println("#"+test_case+" "+answer); - if(temp[newI][newJ]==0) { - temp[newI][newJ] = temp[i][j] + map[newI][newJ]; - dfs(newI,newJ,temp,map,size); - temp[newI][newJ] = 0; - } } + } } \ No newline at end of file From 93d564d60df4e845c4630b323212497158091efe Mon Sep 17 00:00:00 2001 From: monsileI Date: Sun, 31 Jul 2022 23:16:20 +0900 Subject: [PATCH 47/48] =?UTF-8?q?sw=20=EC=97=AD=EB=9F=89=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20bfs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ssafy_avanced_study/no_1226.java | 96 ++++++++++--------- .../src/ssafy_avanced_study/no_1249.java | 56 +++-------- 2 files changed, 65 insertions(+), 87 deletions(-) diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java index 1874fc5..524de28 100644 --- a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java @@ -7,81 +7,91 @@ public class no_1226 { - static int answer = 0; - static int [][] move = {{1,0},{0,1},{-1,0},{0,-1}}; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - int T; - T= Integer.parseInt(br.readLine()); + /* 여러 개의 테스트 케이스가 주어지므로, 각각을 처리합니다. */ - - for(int test_case = 1; test_case <= T; test_case++) + + int[][]move = {{1,0},{0,1},{-1,0},{0,-1}}; + + for(int test_case = 1; test_case <= 10; test_case++) { + Integer.parseInt(br.readLine()); + int[][]map = new int[16][16]; Queue q = new LinkedList<>(); - q.add(new int[] {0,0}); int []start = new int[2]; int []end = new int[2]; + for(int i=0;i<16;i++) { - String str =br.readLine(); + String s = br.readLine(); for(int j=0;j<16;j++) { - map[i][j] = Integer.parseInt(""+str.charAt(j)); - if(map[i][j]==2) { - start[0] = i; - start[1] = j; - }else if(map[i][j]==3) { - end[0] = i; - end[1] = j; - } + map[i][j] = Integer.parseInt(""+s.charAt(j)); + } } + StringBuilder sb = new StringBuilder(); + boolean[][]visited = new boolean[16][16]; + - int[][]temp = new int[16][16]; - temp[start[0]][start[1]] = 0; - + q.add(new int[] {1,1}); + + boolean isTrue = false; - dfs(start[0],start[1],temp,end,map); + while(!q.isEmpty()) { + + int [] c = q.poll(); + int i = c[0]; + int j = c[1]; + + + + + + for(int d=0;d<4;d++) { + + int ni = i+move[d][0]; + int nj = j+move[d][1]; + + if(ni<0||nj<0||15 q = new LinkedList<>(); - - int[][]mov = {{1,0},{0,1},{-1,0},{0,-1}}; - int[][]temp = new int[size][size]; - boolean[][]visited = new boolean[size][size]; - q.add(new int[] {0,0}); - - while(!q.isEmpty()) { - - int []c = q.poll(); - int i = c[0]; - int j = c[1]; - - if(i==size-1 && j==size-1) { - answer = Math.min(answer, temp[i][j]); - continue; - } - if(answer<=temp[i][j]) continue; + int min = Integer.MAX_VALUE; + map[0][0] = Integer.parseInt(br.readLine()); + map[0][1] = Integer.parseInt(br.readLine()); + map[n+1][0] = Integer.parseInt(br.readLine()); + map[n+1][1] = Integer.parseInt(br.readLine()); - for(int d=0;d<4;d++) { - int ni = i + mov[d][0]; - int nj = j + mov[d][1]; - - if(ni<0 || nj<0|| size-1 temp[i][j] + map[ni][nj]) { - visited[ni][nj] = true; - temp[ni][nj] = temp[i][j] + map[ni][nj]; - q.add(new int[] {ni,nj}); - } - - } + for(int i=0;i<=n;i++) { + map[i][0] = Integer.parseInt(br.readLine()); + map[i][1] = Integer.parseInt(br.readLine()); } - System.out.println("#"+test_case+" "+answer); From 5c5507443e2796a87d6036f4ef2365914ef08457 Mon Sep 17 00:00:00 2001 From: monsileI Date: Fri, 16 Sep 2022 20:05:52 +0900 Subject: [PATCH 48/48] =?UTF-8?q?=EB=8B=A4=EC=8B=9C=ED=92=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ssafy_avanced_study/no_1249.java | 101 ++++++++++++------ Basic_Of_Algorithm/src/swea/no_1244.java | 68 ++++++++++++ Basic_Of_Algorithm/src/swea/no_1289.java | 53 +++++++++ Basic_Of_Algorithm/src/test/no_13.java | 54 ++++++++++ 4 files changed, 241 insertions(+), 35 deletions(-) create mode 100644 Basic_Of_Algorithm/src/swea/no_1244.java create mode 100644 Basic_Of_Algorithm/src/swea/no_1289.java create mode 100644 Basic_Of_Algorithm/src/test/no_13.java diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java index 8a703e1..5741327 100644 --- a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java @@ -11,38 +11,69 @@ public class no_1249 { - public static void main(String[] args) throws Exception { - - - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - int T; - T=Integer.parseInt(br.readLine()); - - for(int test_case = 1; test_case <= T; test_case++){ - - int n = Integer.parseInt(br.readLine()); - - int [][]map = new int[n+2][2]; - boolean[] check = new boolean[n+2]; - int[]result = new int[n+2]; - - int min = Integer.MAX_VALUE; - map[0][0] = Integer.parseInt(br.readLine()); - map[0][1] = Integer.parseInt(br.readLine()); - map[n+1][0] = Integer.parseInt(br.readLine()); - map[n+1][1] = Integer.parseInt(br.readLine()); - - for(int i=0;i<=n;i++) { - map[i][0] = Integer.parseInt(br.readLine()); - map[i][1] = Integer.parseInt(br.readLine()); - - } - - - - - } - - } - -} \ No newline at end of file + public static void main(String args[]) throws Exception + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T; + T=Integer.parseInt(br.readLine()); + + for(int test_case = 1; test_case <= T; test_case++){ + + int size =Integer.parseInt(br.readLine()); + + int[][]map = new int[size][size]; + + int answer = Integer.MAX_VALUE; + + + for(int i=0;i q = new LinkedList<>(); + + int[][]mov = {{1,0},{0,1},{-1,0},{0,-1}}; + int[][]temp = new int[size][size]; + boolean[][]visited = new boolean[size][size]; + q.add(new int[] {0,0}); + + while(!q.isEmpty()) { + + int []c = q.poll(); + int i = c[0]; + int j = c[1]; + + if(i==size-1 && j==size-1) { + answer = Math.min(answer, temp[i][j]); + continue; + } + if(answer<=temp[i][j]) continue; + + for(int d=0;d<4;d++) { + int ni = i + mov[d][0]; + int nj = j + mov[d][1]; + + if(ni<0 || nj<0|| size-1 temp[i][j] + map[ni][nj]) { + visited[ni][nj] = true; + temp[ni][nj] = temp[i][j] + map[ni][nj]; + q.add(new int[] {ni,nj}); + } + + } + + } + + System.out.println("#"+test_case+" "+answer); + + + + } + + } + + } \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/swea/no_1244.java b/Basic_Of_Algorithm/src/swea/no_1244.java new file mode 100644 index 0000000..7e37ebf --- /dev/null +++ b/Basic_Of_Algorithm/src/swea/no_1244.java @@ -0,0 +1,68 @@ +package swea; + +import java.util.Scanner; + +public class no_1244 { + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + int size = sc.nextInt(); + + int[]arr = new int[size]; + + for(int i=0;i map = new HashMap<>(); + ArrayList answerList = new ArrayList<>(); + + 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]; + + map.put(id, nick); + + } + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Change")) continue; + + String nick = map.get(id); + String ans = nick + "님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + } + + + String[]answer = new String[answerList.size()]; + + for(int i = 0 ; i< answerList.size();i++) answer[i] = answerList.get(i); + + for(String str : answer)System.out.println(str); + + + } +}