From 97f5ce2db92eadbb7d929a4a4bb38f3bc2c6d1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=8F=99=EC=9A=B0?= Date: Sun, 30 Apr 2023 20:10:11 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98=EB=A8=B8=EC=8A=A4=20?= =?UTF-8?q?=EC=84=AC=EC=97=B0=EA=B2=B0=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/dongwoo.java" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "programmers/\354\204\254\354\227\260\352\262\260\355\225\230\352\270\260/src/dongwoo.java" diff --git "a/programmers/\354\204\254\354\227\260\352\262\260\355\225\230\352\270\260/src/dongwoo.java" "b/programmers/\354\204\254\354\227\260\352\262\260\355\225\230\352\270\260/src/dongwoo.java" new file mode 100644 index 0000000..3335163 --- /dev/null +++ "b/programmers/\354\204\254\354\227\260\352\262\260\355\225\230\352\270\260/src/dongwoo.java" @@ -0,0 +1,56 @@ +import java.util.Arrays; + +public class dongwoo { + public static void main(String[] args) { + + int n = 4; + int[][] costs = new int[][] { { 0, 1, 1 }, { 0, 2, 2 }, { 1, 2, 5 }, { 1, 3, 1 }, { 2, 3, 8 } }; + Solution s = new Solution(); + if (s.solution(n, costs) == 4) { + System.out.println("정답"); + } else { + System.out.println("땡"); + } + + } +} + +class Solution { + int[] union; + + public int solution(int n, int[][] costs) { + Arrays.sort(costs, (o1, o2) -> o1[2] - o2[2]); + int answer = 0; + union = new int[n]; + for (int i = 0; i < union.length; i++) { + union[i] = i; + } + for (int i = 0; i < costs.length; i++) { + if (union(costs[i][0], costs[i][1])) { + answer+=costs[i][2]; + } + } + return answer; + } + + private boolean union(int a, int b) { + b = find(b); + a = find(a); + if (b > a) { + union[b] = a; + return true; + } + if (b < a) { + union[a] = b; + return true; + } + return false; + } + + private int find(int a) { + if (a == union[a]) + return a; + else + return union[a] = find(union[a]); + } +} \ No newline at end of file From 61f9abed80ff26410d9227ca267596927f3e1c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=8F=99=EC=9A=B0?= Date: Sun, 30 Apr 2023 20:17:39 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:=20?= =?UTF-8?q?=EB=B0=B1=EC=A4=80=2011967=20=EB=B6=88=EC=BC=9C=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/dongwoo.java" | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 "baekjoon/11967_\353\266\210\354\274\234\352\270\260/src/dongwoo.java" diff --git "a/baekjoon/11967_\353\266\210\354\274\234\352\270\260/src/dongwoo.java" "b/baekjoon/11967_\353\266\210\354\274\234\352\270\260/src/dongwoo.java" new file mode 100644 index 0000000..85a5806 --- /dev/null +++ "b/baekjoon/11967_\353\266\210\354\274\234\352\270\260/src/dongwoo.java" @@ -0,0 +1,108 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.StringTokenizer; + +public class dongwoo { + static int[] dx = new int[] { 0, 1, 0, -1 }; + static int[] dy = new int[] { 1, 0, -1, 0 }; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + Map> switches = new HashMap<>(); + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + boolean[][] map = new boolean[N][N]; + boolean[][] visited = new boolean[N][N]; + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int[] from = new int[] { Integer.parseInt(st.nextToken()) - 1, Integer.parseInt(st.nextToken()) - 1 }; + int[] to = new int[] { Integer.parseInt(st.nextToken()) - 1, Integer.parseInt(st.nextToken()) - 1 }; + if (!switches.containsKey(new Tuple(from))) { + switches.put(new Tuple(from), new ArrayList<>()); + } + switches.get(new Tuple(from)).add(new Tuple(to)); + } + Queue q = new ArrayDeque<>(); + q.add(new Tuple(new int[] { 0, 0 })); + visited[0][0] = true; + map[0][0] = true; + int cnt = 1; + + while (!q.isEmpty()) { + Tuple now = q.poll(); + + // 현재 위치에서 켤 수 있는 불 다 켜기, 새로 불켠곳이 visited와 인접해있으면 queue에 추가 + for (Tuple pos : switches.getOrDefault(now, new ArrayList<>())) { + int x = pos.tuple[0]; + int y = pos.tuple[1]; + if (!map[x][y]) { + cnt++; + } + map[x][y] = true; + for (int i = 0; i < 4; i++) { + int newX = x + dx[i]; + int newY = y + dy[i]; + boolean val; + try { + val = map[newX][newY]; + } catch (Exception e) { + continue; + } + if (visited[newX][newY] && !visited[x][y]) { + q.add(new Tuple(new int[] { x, y })); + visited[x][y] = true; + break; + } + } + } + // bfs로 주변 탐색하기. + for (int i = 0; i < 4; i++) { + int x = now.tuple[0]; + int y = now.tuple[1]; + int newX = x + dx[i]; + int newY = y + dy[i]; + boolean val; + try { + val = map[newX][newY]; + } catch (Exception e) { + continue; + } + if (visited[newX][newY] || !val) { + continue; + } + q.add(new Tuple(new int[] { newX, newY })); + visited[newX][newY] = true; + + } + } + System.out.println(cnt); + } +} + +class Tuple { + int[] tuple; + + public Tuple(int[] list) { + tuple = list; + } + + @Override + public boolean equals(Object obj) { + return Arrays.equals(tuple, ((Tuple) obj).tuple); + } + + @Override + public int hashCode() { + return 100*tuple[0]+tuple[1]; + } + +} \ No newline at end of file From 2f3f68154646068de21d710bb4643976cc4a4683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=8F=99=EC=9A=B0?= Date: Sun, 30 Apr 2023 20:23:01 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:=20?= =?UTF-8?q?=EB=B0=B1=EC=A4=80=2014908=20=EA=B5=AC=EB=91=90=EC=88=98?= =?UTF-8?q?=EC=84=A0=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/dongwoo.java" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "baekjoon/14908_\352\265\254\353\221\220\354\210\230\354\204\240\352\263\265/src/dongwoo.java" diff --git "a/baekjoon/14908_\352\265\254\353\221\220\354\210\230\354\204\240\352\263\265/src/dongwoo.java" "b/baekjoon/14908_\352\265\254\353\221\220\354\210\230\354\204\240\352\263\265/src/dongwoo.java" new file mode 100644 index 0000000..d042274 --- /dev/null +++ "b/baekjoon/14908_\352\265\254\353\221\220\354\210\230\354\204\240\352\263\265/src/dongwoo.java" @@ -0,0 +1,60 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class dongwoo { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + StringBuilder sb = new StringBuilder(); + Work[] works = new Work[N]; + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + works[i] = new Work(i + 1, Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())); + } + + Arrays.sort(works); + + for (int i = 0; i < N; i++) { + sb.append(works[i].number).append(" "); + } + System.out.println(sb); + } + +} + +class Work implements Comparable { + int number; + int time; + int S; + + public Work(int number, int time, int S) { + this.number = number; + this.time = time; + this.S = S; + } + + @Override + public int compareTo(Work w) { +// double here = Math.round((double) S * 100000 / time); +// double other = Math.round((double) w.S * 100000 / w.time); + double here = (double) S * 100000 / time; + double other = (double) w.S * 100000 / w.time; + // 작업 효율 비교 (보상금 대비 걸리는 시간 ) + if (here != other) { + if (here - other > 0) { + return -1; + } + if (here - other < 0) { + return 1; + } + // 효율이 같으면 시간이 적게 걸리는 순서 + return this.time - w.time; + } + // 시간도 같다면 오름차순 + return this.number - w.number; + } + +} \ No newline at end of file From d5f776c20ec83eb56c392ca18562526e0b2ce507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=8F=99=EC=9A=B0?= Date: Sun, 30 Apr 2023 20:24:38 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:=20?= =?UTF-8?q?=EB=B0=B1=EC=A4=80=2014927=20=EC=A0=84=EA=B5=AC=EB=81=84?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/dongwoo.java" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "baekjoon/14927_\354\240\204\352\265\254\353\201\204\352\270\260/src/dongwoo.java" diff --git "a/baekjoon/14927_\354\240\204\352\265\254\353\201\204\352\270\260/src/dongwoo.java" "b/baekjoon/14927_\354\240\204\352\265\254\353\201\204\352\270\260/src/dongwoo.java" new file mode 100644 index 0000000..31bade7 --- /dev/null +++ "b/baekjoon/14927_\354\240\204\352\265\254\353\201\204\352\270\260/src/dongwoo.java" @@ -0,0 +1,83 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +public class dongwoo { + static boolean[][] map; + static int[] di = new int[] { 0, 0, 1, 0, -1 }; + static int[] dj = new int[] { 0, 1, 0, -1, 0 }; + static int min = Integer.MAX_VALUE; + static int N; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + map = new boolean[N+1][N]; + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + if (Integer.parseInt(st.nextToken()) == 1) { + map[i + 1][j] = true; + } + } + } + for (int i = 0; i < 1< searchable = new ArrayList<>(); + for (int j = 0; j < N; j++) { + if (map[i][j]) { + searchable.add(j); + } + } + if (i == N) { + if (searchable.isEmpty()) { + min = Math.min(min, clickCnt); + } + return; + } + for (int j = 0; j < searchable.size(); j++) { + int pos = searchable.get(j); + clickSwitch(i + 1, pos); + } + checkLine(i + 1, searchable.size() + clickCnt); + for (int j = 0; j < searchable.size(); j++) { + int pos = searchable.get(j); + clickSwitch(i + 1, pos); + } + + } + + private static void clickSwitch(int i, int j) { + for (int k = 0; k < 5; k++) { + int newI = i + di[k]; + int newJ = j + dj[k]; + boolean val; + try { + val = map[newI][newJ]; + } catch (Exception e) { + continue; + } + map[newI][newJ] = !val; + } + } +} From 11e8d7873180e8a18e716fd66a52b9176245cbad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=8F=99=EC=9A=B0?= Date: Sun, 30 Apr 2023 20:29:13 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:=20?= =?UTF-8?q?=EB=B0=B1=EC=A4=80=202904=20=EC=88=98=ED=95=99=EC=9D=80=20?= =?UTF-8?q?=EB=84=88=EB=AC=B4=20=EC=89=AC=EC=9B=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/dongwoo.java" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "baekjoon/2904_\354\210\230\355\225\231\354\235\200\353\204\210\353\254\264\354\211\254\354\233\214/src/dongwoo.java" diff --git "a/baekjoon/2904_\354\210\230\355\225\231\354\235\200\353\204\210\353\254\264\354\211\254\354\233\214/src/dongwoo.java" "b/baekjoon/2904_\354\210\230\355\225\231\354\235\200\353\204\210\353\254\264\354\211\254\354\233\214/src/dongwoo.java" new file mode 100644 index 0000000..d4fc3d6 --- /dev/null +++ "b/baekjoon/2904_\354\210\230\355\225\231\354\235\200\353\204\210\353\254\264\354\211\254\354\233\214/src/dongwoo.java" @@ -0,0 +1,83 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +public class dongwoo { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + int N = Integer.parseInt(br.readLine()); + int[] numbers = new int[N]; + StringTokenizer st = new StringTokenizer(br.readLine()); + Map soinsubunhae = new HashMap<>(); // 등장하는 모든 숫자를 곱해서 소인수분해 때려놓은거 + for (int i = 0; i < N; i++) { + numbers[i] = Integer.parseInt(st.nextToken()); + disAssemble(numbers[i], soinsubunhae); + } + + int maximumValue = 1; + Map soinsubunhaeNanungeo = new HashMap<>(); // 소인수분해 한 결과를 N으로 나눈거 + for (Integer i : soinsubunhae.keySet()) { + int cnt = soinsubunhae.get(i); + if (cnt / N > 0) { + maximumValue *= (int) Math.pow(i, (cnt / N)); + soinsubunhaeNanungeo.put(i, soinsubunhaeNanungeo.getOrDefault(i, 0) + cnt / N); + } + } + sb.append(maximumValue).append(" "); + + // 각 숫자마다 돌면서 부족한 숫자 채워넣기 + int moves = 0; + for (int i = 0; i < N; i++) { + Map res = new HashMap<>(); + disAssemble(numbers[i], res); + for (Integer n : soinsubunhaeNanungeo.keySet()) { + if (soinsubunhaeNanungeo.get(n) > res.getOrDefault(n, 0)) { + moves += soinsubunhaeNanungeo.get(n) - res.getOrDefault(n, 0); + } + } + } + sb.append(moves); + System.out.println(sb); + + } + + // 소인수분해 + public static void disAssemble(int N, Map result) { + if (N == 1) { + return; + } + if (isPrime(N)) { + if (result.containsKey(N)) { + result.put(N, result.get(N) + 1); + } else { + result.put(N, 1); + } + return; + } + for (int i = (int) Math.sqrt(N) + 1; i > 1; i--) { + if (N % i == 0) { + disAssemble(N / i, result); + disAssemble(i, result); + break; + } + } + + } + + private static boolean isPrime(int N) { + if (N < 2) { + return false; + } + for (int i = 2; i <= Math.sqrt(N); i++) { + if (N % i == 0) { + return false; + } + } + return true; + } + +} From 4d93150f2eb0fc667c78f6258d1000e5574fb78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=8F=99=EC=9A=B0?= Date: Sun, 30 Apr 2023 20:38:06 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:=20?= =?UTF-8?q?=EB=B0=B1=EC=A4=80=208980=20=ED=83=9D=EB=B0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/dongwoo.java" | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 "baekjoon/8980_\355\203\235\353\260\260/src/dongwoo.java" diff --git "a/baekjoon/8980_\355\203\235\353\260\260/src/dongwoo.java" "b/baekjoon/8980_\355\203\235\353\260\260/src/dongwoo.java" new file mode 100644 index 0000000..899521a --- /dev/null +++ "b/baekjoon/8980_\355\203\235\353\260\260/src/dongwoo.java" @@ -0,0 +1,109 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class dongwoo { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int C = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(br.readLine()); + // pq 시작점기준 정렬 + PriorityQueue pq = new PriorityQueue<>( + (o1, o2) -> o1.start == o2.start ? o1.end - o2.end : o1.start - o2.start); + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + pq.add(new Parcel(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), + Integer.parseInt(st.nextToken()))); + } + // 마지막 택배도 계산하기 위해 시작지가 N인 짐 추가 + pq.add(new Parcel(N, N, 0)); + + Truck truck = new Truck(C); + while (!pq.isEmpty()) { + Parcel parcel = pq.poll(); + truck.load(parcel); + } + System.out.println(truck.completed); + } +} + +class Truck { + List payload = new ArrayList<>(); + int capacity = 0; // 현재 적재 용량 + int completed = 0; // 배달 완료 박스 + int C; // 총 적재 용량 + + public Truck(int C) { + this.C = C; + } + + public void load(Parcel parcel) { + payload.sort((o1, o2) -> o1.end - o2.end); + // 기존에 있던 짐 중에 내릴 수 있는거 내리고 + for (int i = payload.size() - 1; i >= 0; i--) { + if (payload.get(i).end <= parcel.start) { + completed += payload.get(i).boxes; + capacity -= payload.get(i).boxes; + payload.remove(i); + } + } + + int leftCapa = C - capacity; + if (parcel.boxes <= leftCapa) { + // 용량이 되면 그냥 적재 + payload.add(parcel); + capacity += parcel.boxes; + } else { + // 용량이 안되는 경우 + int size = payload.size(); + int nowBoxes = parcel.boxes; + if (capacity != C) { + // 일단 꽉꽉 눌러 담고 + nowBoxes -= C-capacity; + payload.add(new Parcel(parcel.start, parcel.end, C-capacity)); + capacity = C; + } + for (int i = size-1; i >= 0; i--) { + // 아직 남아있는 짐 중에 바꾸면 이득인거 바꿔가면서 적재함 + if (payload.get(i).end <= parcel.end || nowBoxes == 0) { + break; + } else { + // 기존 짐이 너무 늦게 내리는경우 새치기함 + if (nowBoxes>=payload.get(i).boxes) { + payload.get(i).end = parcel.end; + nowBoxes -= payload.get(i).boxes; + } else { + payload.get(i).boxes -= nowBoxes; + payload.add(new Parcel(parcel.start, parcel.end, nowBoxes)); + break; + } + } + } + } + + } +} + +class Parcel { + int start; + int end; + int boxes; + + public Parcel(int start, int end, int boxes) { + this.start = start; + this.end = end; + this.boxes = boxes; + } + + @Override + public String toString() { + // TODO Auto-generated method stub + return "start : "+start+", end : "+end+", boxes : "+boxes; + } +}