From 91c0b5e41b39cc75b2e8f69ce9b149f88f9dbb6c Mon Sep 17 00:00:00 2001 From: monsileI Date: Thu, 12 May 2022 21:11:43 +0900 Subject: [PATCH 1/2] =?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 2/2] =?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); + + } +}