From ba49487c2642eecd053fb698a42fad675575a256 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Mon, 3 Mar 2025 13:46:43 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[CT]=20Sam?= =?UTF-8?q?=EC=9D=98=20=ED=94=BC=EC=9E=90=ED=95=99=EA=B5=90=5F250303?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354円236円220円355円225円231円352円265円220円.java" | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 "CodeTree/2021-2022353円205円204円/JW_Sam354円235円230円_355円224円274円354円236円220円355円225円231円352円265円220円.java" diff --git "a/CodeTree/2021-2022353円205円204円/JW_Sam354円235円230円_355円224円274円354円236円220円355円225円231円352円265円220円.java" "b/CodeTree/2021-2022353円205円204円/JW_Sam354円235円230円_355円224円274円354円236円220円355円225円231円352円265円220円.java" new file mode 100644 index 00000000..4dae7725 --- /dev/null +++ "b/CodeTree/2021-2022353円205円204円/JW_Sam354円235円230円_355円224円274円354円236円220円355円225円231円352円265円220円.java" @@ -0,0 +1,154 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.StringTokenizer; + +public class JW_Sam의_피자학교 { + + static int n, k; + static Deque dq = new ArrayDeque(); + static int maxValue = 0, minValue = 3001; + static int H, W, R; // 초기 크기 + static int h, w, r; // 변하는 크기 + static int[][] dough; // 피자 도우 + static int[] dy = { 0, -1, 0, 1 }, dx = { -1, 0, 1, 0 }; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + st = new StringTokenizer(br.readLine()); + int v; + for (int i = 0; i < n; i++) { + v = Integer.parseInt(st.nextToken()); + dq.offer(v); + maxValue = Math.max(maxValue, v); + minValue = Math.min(minValue, v); + } + calculateDoughSize(); // 빙글빙글 접을 때의 사이즈 계산 + int time = 0; + while (maxValue - minValue> k) { + initDough(); // 빙글빙글 접기 + press(); // 누르기 + outspread(); // 펼치기 + halfDough(); // 절반씩 접기 + press(); // 누르기 + outspread(); // 펼치기 + judge(); // 최대, 최솟값 갱신 + time++; + } + System.out.println(time); + } + + // 빙글빙글 말 떄의 사이즈 계산 + private static void calculateDoughSize() { + int i = 0; + while ((int) ((i + 4) / 2) * (int) ((i + 3) / 2) <= n) + i++; + H = (i + 3) / 2; + W = (i + 2) / 2; + R = n - H * W; + } + + // 빙글빙글 접기 + private static void initDough() { + h = H; + w = W; + r = R; + dough = new int[h][w + r]; + // 사용하면 안되는 곳에 -1값 삽입 + for (int i = 0; i < h - 1; i++) + for (int j = 0; j < r; j++) + dough[i][w + j] = -1; + int y = h - 1, x = w + r - 1, dir = 0; + while (!dq.isEmpty()) { + dough[y][x] = dq.pollLast(); + if (dough[y][x] == minValue) + dough[y][x]++; + // 부딪히거나 값이 있는 곳이라면 회전 + if (!isValid(y + dy[dir], x + dx[dir]) || dough[y + dy[dir]][x + dx[dir]] != 0) + dir = (dir + 1) % 4; + y += dy[dir]; + x += dx[dir]; + } + } + + // 절반씩 접기 + private static void halfDough() { + h = 4; + w = n / 4; + r = 0; + dough = new int[h][w]; + for (int i = w - 1; i>= 0; i--) + dough[3][i] = dq.pollLast(); + for (int i = w - 1; i>= 0; i--) + dough[2][i] = dq.pollFirst(); + for (int i = 0; i < w; i++) + dough[1][i] = dq.pollFirst(); + for (int i = 0; i < w; i++) + dough[0][i] = dq.pollLast(); + } + + // 누르기 + private static void press() { + int[][] temp = new int[h][w + r]; // 변화량을 저장할 배열 + int ny, nx, d; + for (int y = 0; y < h; y++) + for (int x = 0; x < w + r; x++) { + // 사용하지 않는 칸 스킵 + if (dough[y][x] == -1) + continue; + for (int dir = 2; dir < 4; dir++) { + ny = y + dy[dir]; + nx = x + dx[dir]; + // 좌 하에서 평균 계산 후 맞춰주기 + if (isValid(ny, nx) && dough[ny][nx] != -1) { + d = Math.abs(dough[y][x] - dough[ny][nx]) / 5; + if (dough[y][x]> dough[ny][nx]) { + temp[y][x] -= d; + temp[ny][nx] += d; + } else if (dough[y][x] < dough[ny][nx]) { + temp[y][x] += d; + temp[ny][nx] -= d; + } + } + } + } + // 변화량 계산 + for (int y = 0; y < h; y++) + for (int x = 0; x < w + r; x++) { + if (temp[y][x] == 0) + continue; + dough[y][x] += temp[y][x]; + } + } + + // 펼치기 + private static void outspread() { + maxValue = 0; + minValue = 3001; + for (int x = 0; x < w + r; x++) + for (int y = h - 1; y>= 0; y--) { + if (dough[y][x] == -1) + break; + dq.offer(dough[y][x]); + } + } + + + // 최댓값 최솟값 갱신 + private static void judge() { + for (int y = 0; y < h; y++) + for (int x = 0; x < w; x++) { + maxValue = Math.max(maxValue, dough[y][x]); + minValue = Math.min(minValue, dough[y][x]); + } + } + + // 유효성 검사 + private static boolean isValid(int y, int x) { + return 0 <= y && y < h && 0 <= x && x < w + r; + } +} \ No newline at end of file From 66a4c968f6dbabcc65142e7f23604cdee47ecee3 Mon Sep 17 00:00:00 2001 From: Jewan Baek <116615068+jewan1120@users.noreply.github.com> Date: Thu, 6 Mar 2025 10:24:14 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[BOJ]=201278?= =?UTF-8?q?4=20=EC=9D=B8=ED=95=98=EB=8B=88=EC=B9=B4=20=EA=B3=B5=ED=99=94?= =?UTF-8?q?=EA=B5=AD=5F250304?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/10001-15000353円262円210円/JW_12784.java" | 55 +++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "BOJ/10001-15000353円262円210円/JW_12784.java" diff --git "a/BOJ/10001-15000353円262円210円/JW_12784.java" "b/BOJ/10001-15000353円262円210円/JW_12784.java" new file mode 100644 index 00000000..828222e9 --- /dev/null +++ "b/BOJ/10001-15000353円262円210円/JW_12784.java" @@ -0,0 +1,55 @@ +import java.util.ArrayList; + +public class JW_12784 { + + static final int INF = Integer.MAX_VALUE; + + static ArrayList> graph; + static boolean[] visited; + + public static void main(String[] args) throws Exception { + int t = read(); + StringBuilder sb = new StringBuilder(); + while (t--> 0) { + int n = read(), m = read(); + if(n == 1) { + sb.append(0).append("\n"); + continue; + } + graph = new ArrayList(); + for (int i = 0; i < n + 1; i++) + graph.add(new ArrayList()); + visited = new boolean[n + 1]; + int u, v, d; + for (int i = 0; i < m; i++) { + u = read(); + v = read(); + d = read(); + graph.get(u).add(new int[] { v, d }); + graph.get(v).add(new int[] { u, d }); + } + sb.append(recursive(new int[] { 1, INF })).append("\n"); + } + System.out.println(sb); + } + + private static int recursive(int[] u) { + visited[u[0]] = true; + int minD = 0; + // 자식이 가지는 모든 값 + for (int[] v : graph.get(u[0])) + if (!visited[v[0]]) + minD += recursive(v); + // 현재 섬으로 오는 가중치와 자식으로 가는 간선 가중치의 합을 비교 + return Math.min(minD == 0 ? INF : minD, u[1]); // 갱신되지 않았을 경우 INF 반환 + } + + private static int read() throws Exception { + int c, n = System.in.read() & 15; + while ((c = System.in.read())>= 48) + n = (n << 3) + (n << 1) + (c & 15); + if (c == 13) + System.in.read(); + return n; + } +}

AltStyle によって変換されたページ (->オリジナル) /