From fefab198cc5508029a6c718640b2f19595b86440 Mon Sep 17 00:00:00 2001 From: khkkhk4095 Date: Tue, 2 May 2023 15:23:04 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:boj=20?= =?UTF-8?q?14908.=EA=B5=AC=EB=91=90=EC=88=98=EC=84=A0=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Hyekyoung.java" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "baekjoon/14908_\352\265\254\353\221\220\354\210\230\354\204\240\352\263\265/src/Hyekyoung.java" diff --git "a/baekjoon/14908_\352\265\254\353\221\220\354\210\230\354\204\240\352\263\265/src/Hyekyoung.java" "b/baekjoon/14908_\352\265\254\353\221\220\354\210\230\354\204\240\352\263\265/src/Hyekyoung.java" new file mode 100644 index 0000000..2da2118 --- /dev/null +++ "b/baekjoon/14908_\352\265\254\353\221\220\354\210\230\354\204\240\352\263\265/src/Hyekyoung.java" @@ -0,0 +1,45 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Hyekyoung { + + public static void main(String[] args) throws IOException { + + StringBuilder sb = new StringBuilder(); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + Work[] works = new Work[N]; + double a, b; + StringTokenizer st; + for(int i=0; i{ + int index; + double per; + + public Work(int index, double compensation) { + super(); + this.index = index; + this.per = compensation; + } + + @Override + public int compareTo(Work o) { + return Double.compare(this.per, o.per); + } + } +} \ No newline at end of file From 9dc7460c622479720096f461b1bf626a70cf23b9 Mon Sep 17 00:00:00 2001 From: khkkhk4095 Date: Tue, 2 May 2023 15:26:08 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:boj=20?= =?UTF-8?q?11967.=20=EB=B6=88=EC=BC=9C=EA=B8=B0=20=EC=9D=B4=EA=B1=B0?= =?UTF-8?q?=EB=95=8C=EB=A7=A4=202=EC=8B=9C=EC=97=90=20=EC=9E=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Hyekyoung.java" | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 "baekjoon/11967_\353\266\210\354\274\234\352\270\260/src/Hyekyoung.java" diff --git "a/baekjoon/11967_\353\266\210\354\274\234\352\270\260/src/Hyekyoung.java" "b/baekjoon/11967_\353\266\210\354\274\234\352\270\260/src/Hyekyoung.java" new file mode 100644 index 0000000..566f9a2 --- /dev/null +++ "b/baekjoon/11967_\353\266\210\354\274\234\352\270\260/src/Hyekyoung.java" @@ -0,0 +1,125 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.List; +import java.util.Queue; +import java.util.StringTokenizer; + +public class Hyekyoung { + + static int N, M, cnt = 1; + static boolean[][] map, visited; + static List[] switchMap; + static List room = new ArrayList<>(); + static int[] dr = { -1, 1, 0, 0 }, dc = { 0, 0, -1, 1 }; + static Queue queue = new ArrayDeque<>(); + + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + switchMap = new ArrayList[N * N + 1]; + map = new boolean[N + 1][N + 1]; + visited = new boolean[N + 1][N + 1]; + int x, y, a, b; + + for (int i = 1; i <= N * N; i++) switchMap[i] = new ArrayList<>(); + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + x = Integer.parseInt(st.nextToken()); + y = Integer.parseInt(st.nextToken()); + a = Integer.parseInt(st.nextToken()); + b = Integer.parseInt(st.nextToken()); + + switchMap[(x - 1) * N + y].add(new Point(a, b)); + } + lightOn(); + System.out.println(cnt); + } + + static void lightOn() { + map[1][1] = true; + Point curPoint; + Point p; + int nr, nc, r, c, pr, pc; + queue.offer(new Point(1, 1)); + visited[1][1] = true; + + while (!queue.isEmpty()) { + curPoint = queue.poll(); + r = curPoint.r; + c = curPoint.c; + + for (Point point : switchMap[(r - 1) * N + c]) { + pr = point.r; + pc = point.c; + if (!visited[pr][pc]) { + map[pr][pc] = true; + cnt++; + room.add(new Point(pr, pc)); + } + // 현재 위치에서 불을 켤 수 있는곳은 켜고 리스트에 추가 + } + + for (int i=0; i N || nc > N) continue; + if (!map[nr][nc] || check[nr][nc]) continue; + + check[nr][nc] = true; + queue.offer(new Point(nr, nc)); + } + } + return false; + } + + static class Point { + int r, c; + + public Point(int r, int c) { + super(); + this.r = r; + this.c = c; + } + } +} From 512c70236e31bee4d27820aa8c42d2deb5b620c1 Mon Sep 17 00:00:00 2001 From: khkkhk4095 Date: Tue, 2 May 2023 15:31:26 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:boj=20?= =?UTF-8?q?14927.=20=EC=A0=84=EA=B5=AC=EB=81=84=EA=B8=B0=20=EB=A9=8B?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EB=B9=84=ED=8A=B8=EB=A7=88=EC=8A=A4?= =?UTF-8?q?=ED=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Hyekyoung.java" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "baekjoon/14927_\354\240\204\352\265\254\353\201\204\352\270\260/src/Hyekyoung.java" diff --git "a/baekjoon/14927_\354\240\204\352\265\254\353\201\204\352\270\260/src/Hyekyoung.java" "b/baekjoon/14927_\354\240\204\352\265\254\353\201\204\352\270\260/src/Hyekyoung.java" new file mode 100644 index 0000000..1eb0896 --- /dev/null +++ "b/baekjoon/14927_\354\240\204\352\265\254\353\201\204\352\270\260/src/Hyekyoung.java" @@ -0,0 +1,81 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Hyekyoung { + + static int N, minCnt = 325, push; + static int light[], selected, copy[], l, pos; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + light = new int[N]; + int input; + StringTokenizer st; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + input = Integer.parseInt(st.nextToken()); + if (input == 1) light[i] |= (1 << j); + // 불 켜진 곳 표시 + } + } + selectTop(0, 0); + System.out.println(minCnt < 325 ? minCnt : -1); + } + + // 가장 윗줄 모든 경우 선택 + static void selectTop(int cnt, int selected) { + if (cnt == N) { + lightOff(selected); + return; + } + selectTop(cnt + 1, selected); + selected |= 1 << cnt; + selectTop(cnt + 1, selected); + } + + static void lightOff(int selected) { + copy = light.clone(); + push = 0; + boolean flag = true; + l = selected & (-selected); + // 현재 열 바로 윗줄에서 가장 오른쪽에 위치한 1 비트 위치 찾기 + // 내 윗 전구가 1이면 꺼야함(윗 줄을 끌 수 있는 것은 아랫줄 뿐이니까) + while (l > 0) { + pos = log2(l); + changeLight(0, pos); + selected &= ~(1 << pos); + l = selected & (-selected); + } + for (int i = 1; i < N; i++) { + l = copy[i - 1] & (-copy[i - 1]); + while (l > 0) { + changeLight(i, log2(l)); + l = copy[i - 1] & (-copy[i - 1]); + } + } + for (int i = 0; i < N; i++) { + if (copy[i] > 0) { + flag = false; + break; + } + } + if (flag) minCnt = Math.min(minCnt, push); + } + + static void changeLight(int r, int c) { + push++; + copy[r] ^= 1 << c; + if (r > 0) copy[r - 1] ^= 1 << c; + if (r < N - 1) copy[r + 1] ^= 1 << c; + if (c > 0) copy[r] ^= 1 << c - 1; + if (c < N - 1) copy[r] ^= 1 << c + 1; + } + + static int log2(int x) { + return (int) (Math.log(x) / Math.log(2)); + } +} \ No newline at end of file From 9c841d1ae6ec560fe4fc8be59f979f57b732411d Mon Sep 17 00:00:00 2001 From: khkkhk4095 Date: Tue, 2 May 2023 15:34:44 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=ED=92=80=EC=9D=B4:?= =?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=20=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/Hyekyoung.java" | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 "programmers/\354\204\254\354\227\260\352\262\260\355\225\230\352\270\260/src/Hyekyoung.java" diff --git "a/programmers/\354\204\254\354\227\260\352\262\260\355\225\230\352\270\260/src/Hyekyoung.java" "b/programmers/\354\204\254\354\227\260\352\262\260\355\225\230\352\270\260/src/Hyekyoung.java" new file mode 100644 index 0000000..0940093 --- /dev/null +++ "b/programmers/\354\204\254\354\227\260\352\262\260\355\225\230\352\270\260/src/Hyekyoung.java" @@ -0,0 +1,85 @@ +import java.util.Arrays; + +//간많프 간선이 적으면 크루스칼! +public class Hyekyoung { + 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 Edge implements Comparable { + int from, to, weight; + + public Edge(int from, int to, int weight) { + super(); + this.from = from; + this.to = to; + this.weight = weight; + } + + @Override + public int compareTo(Edge o) { + return Integer.compare(this.weight, o.weight); + } +} + +class Solution { + int V, E; + Edge[] edgeList; + int[] parents; + + void makeSet() { + parents = new int[V]; + for (int i = 0; i < V; i++) { + parents[i] = i; + } + } + + int findSet(int a) { + if (a == parents[a]) return a; + return parents[a] = findSet(parents[a]); + } + + boolean union(int a, int b) { + int aRoot = findSet(a); + int bRoot = findSet(b); + + if (aRoot == bRoot) return false; + + parents[bRoot] = aRoot; + return true; + } + + public int solution(int n, int[][] costs) { + V = n; + E = costs.length; + + edgeList = new Edge[E]; + + for (int i = 0; i < E; i++) { + edgeList[i] = new Edge(costs[i][0], costs[i][1], costs[i][2]); + } + + Arrays.sort(edgeList); + makeSet(); + int result = 0, count = 0; + + for (Edge edge : edgeList) { + if (union(edge.from, edge.to)) { + result += edge.weight; + if (++count == V - 1) break; + } + } + + return result; + } +} \ No newline at end of file