From e2d2a63bde9af00f67b4b9d4ed16c102c6cf81cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81?= Date: Tue, 4 Mar 2025 14:31:39 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81:=20[CT]=20Sam?= =?UTF-8?q?=EC=9D=98=20=ED=94=BC=EC=9E=90=ED=95=99=EA=B5=90=5F250304?= 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" | 214 ++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 "CodeTree/2021-2022\353\205\204/JY_Sam\354\235\230_\355\224\274\354\236\220\355\225\231\352\265\220.java" diff --git "a/CodeTree/2021-2022\353\205\204/JY_Sam\354\235\230_\355\224\274\354\236\220\355\225\231\352\265\220.java" "b/CodeTree/2021-2022\353\205\204/JY_Sam\354\235\230_\355\224\274\354\236\220\355\225\231\352\265\220.java" new file mode 100644 index 00000000..e13bb7c2 --- /dev/null +++ "b/CodeTree/2021-2022\353\205\204/JY_Sam\354\235\230_\355\224\274\354\236\220\355\225\231\352\265\220.java" @@ -0,0 +1,214 @@ +import java.io.*; +import java.util.*; +public class JY_Sam의_피자학교 { + + static int N, K; + static int MX, MY, D; + static int[] arr; + static int[][] g; + // 상 우 하 좌 + static int[] dx = {-1, 0, 1, 0}; + static int[] dy = {0, 1, 0, -1}; + + 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()); + K = Integer.parseInt(st.nextToken()); + + st = new StringTokenizer(br.readLine()); + arr = new int[N]; + for(int i=0; i bottom) { + isStop = true; + break; + } + MX = i; + MY = j; + } + } + D = Math.max(N - (MX*MY), MX+1); + + } + public static void inputWheat() { + int minW = Integer.MAX_VALUE; + for(int i=0; i=0 && x=0 && y=0; i--) { + g[x][y] = arr[i]; + + // 다음 위치 + int nx = x+dx[dir]; + int ny = y+dy[dir]; + // 방향을 바꿔야 함 + if(!inRange(nx, ny, MX, MY) || g[nx][ny] != 0) { + dir = (dir+1)%4; + nx = x+dx[dir]; + ny = y+dy[dir]; + } + x = nx; + y = ny; + } + + // 나머지 바닥 도우 넣기 + x = MX; + y = 0; + for(int i=MX*MY; i g[nx][ny]) tmp[i][j] -= div; + else tmp[i][j] += div; + } + } + } + + for(int i=0; i=0; i--) { + if(g[i][j] == 0) continue; + trr[idx] = g[i][j]; + idx++; + } + } + + arr = trr; + } + public static void halfDough() { + int S = N / 4; + int dir = 1; // 우 -> + + int M = Math.max(S, 4); + g = new int[M][M]; + + // 맨 아래층 + int x = 3; + int y = 0; + for(int i=N-S; i Date: Wed, 5 Mar 2025 09:31:50 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81:=20[BOJ]=201278?= =?UTF-8?q?4=20=EC=9D=B8=ED=95=98=EB=8B=88=EC=B9=B4=EA=B3=B5=ED=99=94?= =?UTF-8?q?=EA=B5=AD=5F250305?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/10001-15000\353\262\210/JY_12784.java" | 71 +++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "BOJ/10001-15000\353\262\210/JY_12784.java" diff --git "a/BOJ/10001-15000\353\262\210/JY_12784.java" "b/BOJ/10001-15000\353\262\210/JY_12784.java" new file mode 100644 index 00000000..b21b2765 --- /dev/null +++ "b/BOJ/10001-15000\353\262\210/JY_12784.java" @@ -0,0 +1,71 @@ +import java.io.*; +import java.util.*; +public class JY_12784 { + + static int N, M; + static List[] g; + static boolean[] visited; + static class Node { + int num, cost; + public Node(int num, int cost) { + this.num = num; + this.cost = cost; + } + @Override + public String toString() { + return "Node [num=" + num + ", cost=" + cost + "]"; + } + + + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int T = Integer.parseInt(st.nextToken()); + StringBuilder sb = new StringBuilder(); + for(int t=0; t(); + } + + for(int i=0; i 자식 순회 + int minCost = 0; + for(Node next: g[now]) { + if(visited[next.num]) continue; + minCost += Math.min(next.cost, dfs(next.num)); + } + + return minCost; + } + +} \ No newline at end of file From f861e4699fc42b6baa403a62b0a9f517a183601a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81?= Date: Wed, 5 Mar 2025 13:15:54 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81:=20[BOJ]=209944?= =?UTF-8?q?=20NxM=20=EB=B3=B4=EB=93=9C=20=EC=99=84=EC=A3=BC=ED=95=98?= =?UTF-8?q?=EA=B8=B0=5F250305?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/5001-10000\353\262\210/JY_9944.java" | 113 ++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 "BOJ/5001-10000\353\262\210/JY_9944.java" diff --git "a/BOJ/5001-10000\353\262\210/JY_9944.java" "b/BOJ/5001-10000\353\262\210/JY_9944.java" new file mode 100644 index 00000000..63301897 --- /dev/null +++ "b/BOJ/5001-10000\353\262\210/JY_9944.java" @@ -0,0 +1,113 @@ +import java.util.*; +import java.io.*; +public class JY_9944 { + + static final int INF = 1000001; + static int N, M; + static char[][] g; + // 상 하 좌 우 + static int[] dx = {-1, 1, 0, 0}; + static int[] dy = {0, 0, -1, 1}; + static boolean[][] visited; + static int eCnt = 0; + static int ans; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + String line; + + int t = 1; + while((line = br.readLine()) != null && !line.isEmpty()) { + st = new StringTokenizer(line); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + g = new char[N][M]; + eCnt = 0; + for(int i=0; i=0 && x=0 && y= ans || cnt >= INF) return; + + visited[x][y] = true; + int nx = x + dx[dir]; + int ny = y + dy[dir]; + + // 현재 방향으로 갈 수 있음 + if(canGo(nx, ny)) { + dfs(nx, ny, dir, mCnt+1, cnt); + } + // 갈 수 없음 -> 방햔 전환 필요(단계 증가) + else { + boolean isMove = false; + for(int i=0; i<4; i++) { + if(i == dir) continue; + nx = x + dx[i]; + ny = y + dy[i]; + if(!canGo(nx, ny)) continue; + + isMove = true; + dfs(nx, ny, i, mCnt+1, cnt+1); + } + + } + visited[x][y] = false; + } + +} From 646714060c96441ebd97e7cbcf846ed056cbafe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81?= Date: Wed, 5 Mar 2025 14:20:27 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81:=20[SOL]=20?= =?UTF-8?q?=ED=97=A4=EB=B9=84=20=EC=9C=A0=EC=A0=80=EA=B0=80=20=EC=86=8C?= =?UTF-8?q?=EC=9C=A0=ED=95=9C=20=EC=9E=A5=EC=86=8C=5F250305?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\234\240\355\225\234_\354\236\245\354\206\214.sql" | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 "SQL/25\354\243\274\354\260\250/JY_\355\227\244\353\271\204_\354\234\240\354\240\200\352\260\200_\354\206\214\354\234\240\355\225\234_\354\236\245\354\206\214.sql" diff --git "a/SQL/25\354\243\274\354\260\250/JY_\355\227\244\353\271\204_\354\234\240\354\240\200\352\260\200_\354\206\214\354\234\240\355\225\234_\354\236\245\354\206\214.sql" "b/SQL/25\354\243\274\354\260\250/JY_\355\227\244\353\271\204_\354\234\240\354\240\200\352\260\200_\354\206\214\354\234\240\355\225\234_\354\236\245\354\206\214.sql" new file mode 100644 index 00000000..4a7c109d --- /dev/null +++ "b/SQL/25\354\243\274\354\260\250/JY_\355\227\244\353\271\204_\354\234\240\354\240\200\352\260\200_\354\206\214\354\234\240\355\225\234_\354\236\245\354\206\214.sql" @@ -0,0 +1,8 @@ +-- 헤비 유저가 소유한 장소 +-- https://school.programmers.co.kr/learn/courses/30/lessons/77487 + +SELECT +* +FROM PLACES +WHERE HOST_ID IN (SELECT HOST_ID FROM PLACES GROUP BY HOST_ID HAVING COUNT(ID) >=2) +ORDER BY ID \ No newline at end of file From a449efec4481ac8f963bdcaaf8f01a934b964c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81?= Date: Thu, 6 Mar 2025 13:24:06 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81:=20[PG]=20?= =?UTF-8?q?=EC=99=84=EC=A0=84=EB=B2=94=EC=A3=84=5F250306?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level2/JY_389480.java | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Programmers/Level2/JY_389480.java diff --git a/Programmers/Level2/JY_389480.java b/Programmers/Level2/JY_389480.java new file mode 100644 index 00000000..b821d67d --- /dev/null +++ b/Programmers/Level2/JY_389480.java @@ -0,0 +1,45 @@ +import java.util.*; +class JY_389480 { + + static final int INF = 1000; + static int[][] dp; + static int SIZE, M; + + public int solution(int[][] info, int n, int m) { + int answer = 0; + SIZE = info.length; + M = m; + + dp = new int[SIZE][M]; + // dp[i][j] : i번째 물건까지 탐색했고 B의 흔적이 j일때, A의 최소 흔적 + // -1로 초기화 : 방문 체크 여부 + for(int i=0; i= n) return -1; + return answer; + } + public static int dfs(int[][] info, int i, int j) { + // B가 훔친 것이 M이상이면 불가능 stop + if(j >= M) return INF; + // 모든 물건 탐색 -> 더이상 탐색할 물건 없음 + if(i == info.length) return 0; + + // 이미 i번쨰 물건을 B가 훔쳤음(== 이미 최솟값 갱신됨) + if(dp[i][j] != -1) return dp[i][j]; + + + int a = info[i][0]; + int b = info[i][1]; + + // A가 훔치는 경우 + int ca = dfs(info, i+1, j) + a; + // B가 훔치는 경우 + int cb = dfs(info, i+1, j+b); + + return dp[i][j] = Math.min(ca, cb); + } +} \ No newline at end of file From cb23ba05b2d04502c646661ea70dc60bd43d030f Mon Sep 17 00:00:00 2001 From: yeong Date: Sat, 8 Mar 2025 16:53:05 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=98=81:=20[BOJ]=203207?= =?UTF-8?q?0=20=EC=83=89=EA=B9=94=20=EB=AA=A8=EC=9C=BC=EA=B8=B0=5F250308?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/30000-35000\353\262\210/JY_32070.java" | 120 ++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 "BOJ/30000-35000\353\262\210/JY_32070.java" diff --git "a/BOJ/30000-35000\353\262\210/JY_32070.java" "b/BOJ/30000-35000\353\262\210/JY_32070.java" new file mode 100644 index 00000000..97acb3d9 --- /dev/null +++ "b/BOJ/30000-35000\353\262\210/JY_32070.java" @@ -0,0 +1,120 @@ +import java.io.*; +import java.util.*; + +public class JY_32070 { + static int N; + // cnt[i] 그룹의 공의 개수 == 그룹의 크기 + // rank[i] 트리의 깊이 + // toParis[] 한 그룹에서 상단에 위치한 공의 개수 + static int[] parent, cnt, topPairs; + static boolean[] solved; + static List[] ball; + + static int find(int u) { + if (parent[u] == u) return u; + return parent[u] = find(parent[u]); + } + + static void union(int a, int b) { + int pa = find(a); + int pb = find(b); + + if(pa == pb) return; + if(pa < pb) { + parent[pb] = pa; + cnt[pa] += cnt[pb]; + } else { + parent[pa] = pb; + cnt[pb] += cnt[pa]; + } + + } + + // 해당 집합의 크기 반환 + static int getCnt(int u) { + return cnt[find(u)]; + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + ball = new ArrayList[N + 1]; + for (int i = 1; i <= N; i++) { + ball[i] = new ArrayList<>(); + } + + parent = new int[N + 1]; +// rank = new int[N + 1]; + cnt = new int[N + 1]; + topPairs = new int[N + 1]; + solved = new boolean[N + 1]; + + // 초기화 == 각 상자가 그룹장 + for (int i = 1; i <= N; i++) { + parent[i] = i; + cnt[i] = 1; + } + + for (int i = 1; i <= N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + // 색깔이 a인 공의 절대적인 상자 위치 + ball[a].add(i * 2); + // 색깔이 b인 공의 절대적인 상자 위치 + ball[b].add(i * 2 + 1); + } + + System.out.println(Arrays.toString(ball)); + + // 같은 색 공이 있는 상자들을 병합 + for (int i = 1; i <= N; i++) { + union(ball[i].get(0) / 2, ball[i].get(1) / 2); + } + + System.out.println(">> parent: "+Arrays.toString(parent)); + System.out.println(">> cnt: "+Arrays.toString(cnt)); + // cnt[i] : i번째 상자가 속한 사이클의 상자의 개수 + + // 루트 노드의 topPairs 개수 증가 + // 짝수 : 상자의 상단에 있음 + // 홀수 : 상자의 하단에 있음 + for (int i = 1; i <= N; i++) { + // 색깔이 i인 공이 모두 각 상자의 상단에 있음 + if (ball[i].get(0) % 2 == 0 && ball[i].get(1) % 2 == 0) { + int rootIdx = find(ball[i].get(0) / 2); + System.out.println("i:"+i+" root:"+rootIdx); + topPairs[rootIdx]++; + } + } + + System.out.println("top: "+Arrays.toString(topPairs)); + + // 상자 그룹이 2개 이상이면 불가능 (-1 출력) + for (int i = 1; i <= N; i++) { + int rootIdx = find(ball[i].get(0) / 2); + if (topPairs[rootIdx] >= 2) { + System.out.println("-1"); + return; + } + } + + int ans = 0; + + // 최소 이동 횟수 계산 + for (int i = 1; i <= N; i++) { + int rootIdx = find(ball[i].get(0) / 2); + + if (solved[rootIdx]) continue; + + solved[rootIdx] = true; + int x = cnt[rootIdx]; + + if (x >= 2) ans += x + 1; + } + + System.out.println(ans); + } +}