From 01b3d86f3df4b296d0ffb4cd41a3fbb0bd31d853 Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月11ζ—₯ 08:47:14 +0900 Subject: [PATCH 01/10] =?UTF-8?q?dosc:=2010=EC=A3=BC=EC=B0=A8=20=EB=A6=AC?= =?UTF-8?q?=EB=93=9C=EB=AF=B8=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 738cabb7..194a58e9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # AlgorithmStudy -
+ ## πŸ‘¨β€πŸ’» μŠ€ν„°λ””μ› From 3908ef24d276fabaac7057e4a81e5dc776733071 Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月11ζ—₯ 15:14:31 +0900 Subject: [PATCH 02/10] =?UTF-8?q?=EB=B0=B0=EC=88=98=EB=B9=88:=20[CT]=20?= =?UTF-8?q?=ED=9A=8C=EC=A0=84=ED=95=98=EB=8A=94=20=EB=B9=99=ED=95=98=5F241?= =?UTF-8?q?111?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353212円224円_353円271円231円355円225円230円.java" | 159 ++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 "CodeTree/2019-2020353円205円204円/SB_355円232円214円354円240円204円355円225円230円353円212円224円_353円271円231円355円225円230円.java" diff --git "a/CodeTree/2019-2020353円205円204円/SB_355円232円214円354円240円204円355円225円230円353円212円224円_353円271円231円355円225円230円.java" "b/CodeTree/2019-2020353円205円204円/SB_355円232円214円354円240円204円355円225円230円353円212円224円_353円271円231円355円225円230円.java" new file mode 100644 index 00000000..663a7fe9 --- /dev/null +++ "b/CodeTree/2019-2020353円205円204円/SB_355円232円214円354円240円204円355円225円230円353円212円224円_353円271円231円355円225円230円.java" @@ -0,0 +1,159 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Queue; +import java.util.StringTokenizer; + +public class SB_νšŒμ „ν•˜λŠ”_λΉ™ν•˜ { + static int N, Q, M; + static int[][] board; + static boolean[][] visited; + static int[] dx = {-1, 1, 0, 0}; + static int[] dy = {0, 0, -1, 1}; + static int area = 0; + static int mx = 0; + private static void bfs(int x, int y) { + Queue que = new ArrayDeque(); + que.offer(new Node(x, y)); + visited[x][y] = true; + + int size = 0; + while (!que.isEmpty()) { + Node cur = que.poll(); + area += board[cur.x][cur.y]; + size++; + + for (int i = 0; i < 4; i++) { + int nx = cur.x + dx[i]; + int ny = cur.y + dy[i]; + if (!isValid(nx, ny) || visited[nx][ny] || board[nx][ny]==0) continue; + que.offer(new Node(nx, ny)); + visited[nx][ny] = true; + } + } + mx = Math.max(mx, size); + } + + private static void calIceGroup() { + visited = new boolean[M][M]; + + for (int i = 0; i < M; i++) { + for (int j = 0; j < M; j++) { + if (!visited[i][j] && board[i][j]> 0) { + bfs(i, j); + } + } + } + } + private static void meltIce() { + boolean[][] check = new boolean[M][M]; + + // 녹을 λΉ™ν•˜ 체크 + for (int i = 0; i < M; i++) { + for (int j = 0; j < M; j++) { + if (board[i][j]==0) continue; // μ–ΌμŒμ΄ μ•„λ‹Œ 곳은 νŒ¨μ“° + int cnt = 0; + for (int k = 0; k < 4; k++) { + int nx = i + dx[k]; + int ny = j + dy[k]; + if (isValid(nx, ny) && board[nx][ny]>0) cnt++; + } + if (cnt < 3) check[i][j] = true; + } + } + + // 체크된 λΉ™ν•˜ 녹이기 + for (int i = 0; i < M; i++) { + for (int j = 0; j < M; j++) { + if (check[i][j]) board[i][j]--; + } + } + } + + private static boolean isValid(int x, int y) { + return 0<=x && x 0) { + int L = Integer.parseInt(st.nextToken()); + if (L> 0) rotate(L); + meltIce(); // μ–ΌμŒ λ…ΉκΈ° + } + + // μ–ΌμŒκ΅°μ§‘ κ΅¬ν•˜κΈ° + calIceGroup(); + + System.out.println(area); + System.out.println(mx); + } + + static class Node{ + int x, y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + } +} \ No newline at end of file From 6fe27813a3118c822430a9c96edf52b2a2bcd85a Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月13ζ—₯ 10:40:57 +0900 Subject: [PATCH 03/10] =?UTF-8?q?=EB=B0=B0=EC=88=98=EB=B9=88:=20[BOJ]=2020?= =?UTF-8?q?96=20=EB=82=B4=EB=A0=A4=EA=B0=80=EA=B8=B0=5F241113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/1000-5000353円262円210円/SB_2096.java" | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "BOJ/1000-5000353円262円210円/SB_2096.java" diff --git "a/BOJ/1000-5000353円262円210円/SB_2096.java" "b/BOJ/1000-5000353円262円210円/SB_2096.java" new file mode 100644 index 00000000..85a794f0 --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/SB_2096.java" @@ -0,0 +1,54 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class SB_2096 { + static int N; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + int[][] dpMx = new int[2][3]; // 이전값, ν˜„μž¬κ°’ + int[][] dpMn = new int[2][3]; + + st = new StringTokenizer(br.readLine()); // 초기 0ν–‰ κ°’ μ„€μ • + for (int i = 0; i < 3; i++) { + int x = Integer.parseInt(st.nextToken()); + dpMx[0][i] = x; + dpMx[1][i] = x; + dpMn[0][i] = x; + dpMn[1][i] = x; + } + + for (int i = 1; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + dpMx[1][0] = Math.max(dpMx[0][0], dpMx[0][1]) + a; + dpMx[1][1] = Math.max(dpMx[0][0], Math.max(dpMx[0][1], dpMx[0][2])) + b; + dpMx[1][2] = Math.max(dpMx[0][1], dpMx[0][2]) + c; + + dpMn[1][0] = Math.min(dpMn[0][0], dpMn[0][1]) + a; + dpMn[1][1] = Math.min(dpMn[0][0], Math.min(dpMn[0][1], dpMn[0][2])) + b; + dpMn[1][2] = Math.min(dpMn[0][1], dpMn[0][2]) + c; + + // 이전값을 μ—…λ°μ΄νŠΈλœ ν˜„μž¬κ°’ μ—…λ°μ΄νŠΈ + dpMx[0][0] = dpMx[1][0]; + dpMx[0][1] = dpMx[1][1]; + dpMx[0][2] = dpMx[1][2]; + + dpMn[0][0] = dpMn[1][0]; + dpMn[0][1] = dpMn[1][1]; + dpMn[0][2] = dpMn[1][2]; + } + + int mx = Math.max(dpMx[0][0], Math.max(dpMx[0][1], dpMx[0][2])); + int mn = Math.min(dpMn[0][0], Math.min(dpMn[0][1], dpMn[0][2])); + + System.out.println(mx + " " + mn); + } +} From 064ddcfa60382f32cf13c9a8244cc74fc904f603 Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月13ζ—₯ 11:05:44 +0900 Subject: [PATCH 04/10] =?UTF-8?q?=EB=B0=B0=EC=88=98=EB=B9=88:=20[BOJ]=2016?= =?UTF-8?q?13=20=EC=97=AD=EC=82=AC=5F241113?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/1000-5000353円262円210円/SB_1613.java" | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "BOJ/1000-5000353円262円210円/SB_1613.java" diff --git "a/BOJ/1000-5000353円262円210円/SB_1613.java" "b/BOJ/1000-5000353円262円210円/SB_1613.java" new file mode 100644 index 00000000..9364025e --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/SB_1613.java" @@ -0,0 +1,56 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class SB_1613 { + static int N, K; + static int[][] order; + static int INF = Integer.MAX_VALUE>> 2; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + order = new int[N + 1][N + 1]; + for (int i = 1; i < N + 1; i++) { + Arrays.fill(order[i], INF); + order[i][i] = 0; + } + + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + order[a][b] = 1; + } + + for (int k = 1; k < N + 1; k++) { + for (int i = 1; i < N + 1; i++) { + for (int j = 1; j < N + 1; j++) { + if (order[i][j]> order[i][k] + order[k][j]) { + order[i][j] = order[i][k] + order[k][j]; + } + } + } + } + + int S = Integer.parseInt(br.readLine()); + while (S--> 0) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + if (order[a][b] != INF) sb.append(-1); + else if (order[b][a] != INF) sb.append(1); + else sb.append(0); + sb.append('\n'); + } + + System.out.println(sb); + } +} From 55abddcb50ed5603e8b7333ab4aba07cfc94e688 Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月14ζ—₯ 18:20:34 +0900 Subject: [PATCH 05/10] =?UTF-8?q?=EB=B0=B0=EC=88=98=EB=B9=88:=20[PG]=20150?= =?UTF-8?q?366=20=ED=91=9C=20=EB=B3=91=ED=95=A9=5F241114?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level3/SB_150366.java | 125 ++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 Programmers/Level3/SB_150366.java diff --git a/Programmers/Level3/SB_150366.java b/Programmers/Level3/SB_150366.java new file mode 100644 index 00000000..61bcf05e --- /dev/null +++ b/Programmers/Level3/SB_150366.java @@ -0,0 +1,125 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +class SB_150366 { + static String[] board = new String[2500]; + static int[] parents = new int[2500]; + static List ans = new ArrayList(); + static String empty = "EMPTY"; + static int N = 2500; + + private static void print(String[] cmd) { + int r = Integer.parseInt(cmd[1])-1; + int c = Integer.parseInt(cmd[2])-1; + int idx = r*50+c; + int pIdx = find(idx); + + if (board[pIdx]==null) ans.add(empty); + else ans.add(board[pIdx]); + } + private static void unmerge(String[] cmd) { + int r = Integer.parseInt(cmd[1])-1; + int c = Integer.parseInt(cmd[2])-1; + + int idx = r*50+c; // μ„ νƒλœ r,c μ…€ 인덱슀 + int p = find(idx); // ν•΄λ‹Ή μ…€μ˜ λΆ€λͺ¨ 인덱슀 (병합 λŒ€ν‘œ) + String val = board[p]; // λΆ€λͺ¨ 인덱슀의 κ°’ (병합 λŒ€ν‘œ κ°’) + + // 병합 ν•΄μ œλ  μ…€ 좔적 리슀트 + List candi = new ArrayList(); + + // λ³‘ν•©ν•΄μ œν•  μ…€ ν›„λ³΄λ‘œ λ‹΄κΈ° + for (int i = 0; i < N; i++) { + if (find(i) == p) { + candi.add(i); + } + } + + // λ³‘ν•©ν•΄μ œν•  μ…€ κ°’ 볡원 + for (Integer cell : candi){ + parents[cell] = cell; + board[cell] = null; + } + + // νƒ€κ²Ÿ λ³‘ν•©ν•΄μ œ 셀은 μ›λž˜ κ°’ μœ μ§€ + board[idx] = val; + } + private static int find(int x) { + if (x!=parents[x]) parents[x] = find(parents[x]); + return parents[x]; + } + + private static void union(int a, int b, String val) { + if (a != b) { + parents[b] = a; // b의 λΆ€λͺ¨λ₯Ό a둜 μ„€μ • + board[a] = val; // 병합 λŒ€ν‘œμ—λ§Œ κ°’ μ„€μ • + + // b와 μ—°κ²°λœ λͺ¨λ“ μ…€μ— μƒˆλ‘œμš΄ λΆ€λͺ¨ aμ„€μ • + for (int i = 0; i < N; i++) { + if (find(i)==b) parents[i] = a; + } + } + } + + private static void merge(String[] cmd) { + int r1 = Integer.parseInt(cmd[1])-1; + int c1 = Integer.parseInt(cmd[2])-1; + int r2 = Integer.parseInt(cmd[3])-1; + int c2 = Integer.parseInt(cmd[4])-1; + + // 각 μ…€μ˜ λΆ€λͺ¨ 인덱슀 + int p1 = find(50*r1+c1); + int p2 = find(50*r2+c2); + + // λŒ€ν‘œ μ…€ κ°’ κ²°μ • + if (p1 != p2) { + String val = board[p1] != null ? board[p1] : board[p2]; + union(p1, p2, val); + } + } + + private static void updateOne(String[] cmd) { + int r = Integer.parseInt(cmd[1]) - 1; + int c = Integer.parseInt(cmd[2]) - 1; + + // μ„ νƒν•œ μ…€μ˜ λΆ€λͺ¨ κ°’ μˆ˜μ • + int idx = 50*r+c; // μ„ νƒλœ κ°’μ˜ 인덱슀 + int p = find(idx); // ν•΄λ‹Ή 인덱슀의 λΆ€λͺ¨(병합 λŒ€ν‘œ) + board[p] = cmd[3]; // 병합 λŒ€ν‘œκ°’ μ—…λ°μ΄νŠΈ + } + private static void updateAll(String[] cmd) { + String target = cmd[1]; + String val = cmd[2]; + for (int i = 0; i < N; i++) { // λ°°μ—΄ μˆœνšŒν•˜λ©΄μ„œ κ°’ λ³€κ²½ + if (Objects.equals(board[i], target)) board[i] = val; // nullκ°’ 처리(Objects.equals) + } + } + public static String[] solution(String[] commands) { + // λ³‘ν•©ν…Œμ΄λΈ” μ΄ˆκΈ°ν™” + for (int i = 0; i < N; i++) { + parents[i] = i; + } + + for (String cmds : commands) { + String[] cmd = cmds.split(" "); + switch (cmd[0]) { + case "UPDATE": + if (cmd.length == 4) updateOne(cmd); + else updateAll(cmd); + break; + case "MERGE": + merge(cmd); + break; + case "UNMERGE": + unmerge(cmd); + break; + case "PRINT": + print(cmd); + break; + } + } + + return ans.toArray(new String[0]); + } +} From cbf1e99ad3ae9dcb6ba7fb83d5e9a3420f15dd89 Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月15ζ—₯ 09:30:55 +0900 Subject: [PATCH 06/10] =?UTF-8?q?=EB=B0=B0=EC=88=98=EB=B9=88:=20[PG]=20181?= =?UTF-8?q?188=20=EC=9A=94=EA=B2=A9=20=EC=8B=9C=EC=8A=A4=ED=85=9C=5F241115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level2/SB_181188.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Programmers/Level2/SB_181188.java diff --git a/Programmers/Level2/SB_181188.java b/Programmers/Level2/SB_181188.java new file mode 100644 index 00000000..ce75541c --- /dev/null +++ b/Programmers/Level2/SB_181188.java @@ -0,0 +1,16 @@ +import java.util.*; + +class SB_181188 { + public int solution(int[][] targets) { + Arrays.sort(targets, ((o1, o2) -> o1[1]-o2[1])); + + int cnt = 1; + int pos = targets[0][1]; + for (int[] t : targets) { + if (t[0] < pos) continue; + pos = t[1]; + cnt++; + } + return cnt; + } +} \ No newline at end of file From e81a503df6137e28a36555bc4c4d6f1391b43803 Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月15ζ—₯ 09:42:04 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=EB=B0=B0=EC=88=98=EB=B9=88:=20[PG]=20428?= =?UTF-8?q?84=20=EB=8B=A8=EC=86=8D=EC=B9=B4=EB=A9=94=EB=9D=BC=5F241115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level3/SB_42884.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Programmers/Level3/SB_42884.java diff --git a/Programmers/Level3/SB_42884.java b/Programmers/Level3/SB_42884.java new file mode 100644 index 00000000..7bc5b3f0 --- /dev/null +++ b/Programmers/Level3/SB_42884.java @@ -0,0 +1,17 @@ +import java.util.*; + +class SB_42884 { + public int solution(int[][] routes) { + Arrays.sort(routes, ((o1, o2) -> o1[1]-o2[1])); + + int cnt = 1; + int pos = routes[0][1]; + + for(int[] r : routes){ + if(r[0] <= pos) continue; + pos = r[1]; + cnt++; + } + return cnt; + } +} \ No newline at end of file From 5b85a0c20c6001a58a9e9b13e8d704dd6870b7d5 Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月15ζ—₯ 10:24:34 +0900 Subject: [PATCH 08/10] =?UTF-8?q?=EB=B0=B0=EC=88=98=EB=B9=88:=20[SQL]=20St?= =?UTF-8?q?udents=20and=20Examinations=5F241115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SB_Students and Examinations.sql" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "SQL/10354円243円274円354円260円250円/SB_Students and Examinations.sql" diff --git "a/SQL/10354円243円274円354円260円250円/SB_Students and Examinations.sql" "b/SQL/10354円243円274円354円260円250円/SB_Students and Examinations.sql" new file mode 100644 index 00000000..aed30238 --- /dev/null +++ "b/SQL/10354円243円274円354円260円250円/SB_Students and Examinations.sql" @@ -0,0 +1,22 @@ +-- 각 학생이 각 μ‹œν—˜μ— μ‘μ‹œν•œ 횟수λ₯Ό μ°ΎκΈ° μœ„ν•œ ν•΄κ²°μ±… + +-- CROSS JOIN 이용 +SELECT st.student_id, st.student_name ,sb.subject_name, + COUNT(e.student_id) AS attended_exams +FROM Students st +CROSS JOIN Subjects sb +LEFT JOIN Examinations e + ON e.student_id = st.student_id + AND e.subject_name = sb.subject_name +GROUP BY st.student_id, st.student_name, sb.subject_name +ORDER BY st.student_id, st.student_name, sb.subject_name + +-- CORSS JOIN 이용X, (잘λͺ»λœ κ°’ λ°˜ν™˜ κ°€λŠ₯) +SELECT a.student_id, a.student_name, b.subject_name, + COUNT(c.subject_name) AS attended_exams +FROM Students a +JOIN Subjects b +LEFT JOIN Examinations c ON a.student_id = c.student_id AND b.subject_name = c.subject_name +GROUP BY a.student_id, a.student_name, b.subject_name +ORDER BY a.student_id, b.subject_name; + From 9ba5059db149a7b4a61210268593044c807d2bb5 Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月16ζ—₯ 01:15:44 +0900 Subject: [PATCH 09/10] =?UTF-8?q?=EB=B0=B0=EC=88=98=EB=B9=88:=20[SQL]=20?= =?UTF-8?q?=EC=9E=85=EC=96=91=20=EC=8B=9C=EA=B0=81=20=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B8=B0(2)=5F241115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... 352円265円254円355円225円230円352円270円260円.sql" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "SQL/10354円243円274円354円260円250円/SB_354円236円205円354円226円221円 354円213円234円352円260円201円 352円265円254円355円225円230円352円270円260円.sql" diff --git "a/SQL/10354円243円274円354円260円250円/SB_354円236円205円354円226円221円 354円213円234円352円260円201円 352円265円254円355円225円230円352円270円260円.sql" "b/SQL/10354円243円274円354円260円250円/SB_354円236円205円354円226円221円 354円213円234円352円260円201円 352円265円254円355円225円230円352円270円260円.sql" new file mode 100644 index 00000000..1152a820 --- /dev/null +++ "b/SQL/10354円243円274円354円260円250円/SB_354円236円205円354円226円221円 354円213円234円352円260円201円 352円265円254円355円225円230円352円270円260円.sql" @@ -0,0 +1,60 @@ +-- 0μ‹œλΆ€ν„° 23μ‹œκΉŒμ§€, 각 μ‹œκ°„λŒ€λ³„λ‘œ μž…μ–‘μ΄ λͺ‡ κ±΄μ΄λ‚˜ λ°œμƒν–ˆλŠ”μ§€ 쑰회 + +-- RECURSIVE μ‚¬μš© +WITH RECURSIVE TM AS( + SELECT 0 AS HOUR + UNION ALL + SELECT HOUR+1 FROM TM WHERE HOUR < 23 +) + +SELECT A.HOUR, IFNULL(B.COUNT, 0) AS COUNT +FROM TM A LEFT JOIN ( + SELECT HOUR(DATETIME) AS HOUR, COUNT(HOUR(DATETIME)) AS COUNT + FROM ANIMAL_OUTS + GROUP BY HOUR(DATETIME) +) B ON A.HOUR = B.HOUR + +-- μ„Έμ…˜ λ³€μˆ˜ μ‚¬μš© 방식 +SET @HOUR := -1; + +SELECT (@HOUR := @HOUR+1) as HOUR, +(SELECT COUNT(*) FROM ANIMAL_OUTS WHERE HOUR(DATETIME) =@HOUR) AS COUNT +FROM ANIMAL_OUTS +WHERE @HOUR < 23 + +-- ν”„λ‘œμ‹œμ € μ‚¬μš© +DELIMITER $$ + +CREATE PROCEDURE GetAnimalCountByHour() +BEGIN + -- ν”„λ‘œμ‹œμ € λ‚΄λΆ€μ—μ„œ μ‚¬μš©ν•  λ³€μˆ˜ μ„ μ–Έ + DECLARE i INT DEFAULT 0; -- i, 반볡문의 μΉ΄μš΄ν„° μ—­ν• , 0으둜 μ΄ˆκΈ°ν™” + DECLARE hour_count INT; -- 각 μ‹œκ°„λŒ€μ˜ λ ˆμ½”λ“œ 개수 μ €μž₯ + + -- μ‹œκ°„λ³„ κ²°κ³Όλ₯Ό μ €μž₯ν•  μž„μ‹œ ν…Œμ΄λΈ” 생성 + CREATE TEMPORARY TABLE HourlyCounts (HOUR INT, COUNT INT); + + -- 0μ‹œλΆ€ν„° 23μ‹œκΉŒμ§€ 반볡 + WHILE i < 24 DO + -- νŠΉμ • μ‹œκ°„λŒ€μ˜ COUNT 값을 계산 + SELECT COUNT(*) INTO hour_count + FROM ANIMAL_OUTS + WHERE HOUR(DATETIME) = i; + + -- κ²°κ³Όλ₯Ό μž„μ‹œ ν…Œμ΄λΈ”μ— μ €μž₯ + INSERT INTO HourlyCounts (HOUR, COUNT) VALUES (i, hour_count); + + -- μ‹œκ°„ 증가 + SET i = i + 1; + END WHILE; + + -- κ²°κ³Ό 좜λ ₯ + SELECT * FROM HourlyCounts; + + -- μž„μ‹œ ν…Œμ΄λΈ” μ‚­μ œ + DROP TEMPORARY TABLE HourlyCounts; +END$$ + +DELIMITER ; + +CALL GetAnimalCountByHour(); \ No newline at end of file From 083e407490497fe5496062c14b5120459bb4c3f0 Mon Sep 17 00:00:00 2001 From: baexxbin Date: 2024εΉ΄11月16ζ—₯ 01:27:37 +0900 Subject: [PATCH 10/10] =?UTF-8?q?=EB=B0=B0=EC=88=98=EB=B9=88:=20[BOJ]=2029?= =?UTF-8?q?55=20=EC=8A=A4=EB=8F=84=EC=BF=A0=20=ED=92=80=EA=B8=B0(=ED=8B=80?= =?UTF-8?q?=EB=A6=B0=EC=BD=94=EB=93=9C)=5F241116?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/1000-5000353円262円210円/SB_2955.java" | 125 +++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 "BOJ/1000-5000353円262円210円/SB_2955.java" diff --git "a/BOJ/1000-5000353円262円210円/SB_2955.java" "b/BOJ/1000-5000353円262円210円/SB_2955.java" new file mode 100644 index 00000000..d381a5ad --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/SB_2955.java" @@ -0,0 +1,125 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class SB_2955 { + static int[][] board = new int[9][9]; + static boolean[][] row = new boolean[9][10]; + static boolean[][] col = new boolean[9][10]; + static boolean[][] box = new boolean[9][10]; + + + private static boolean crossHatching(int num) { + boolean flag = false; + for (int i = 0; i < 9; i++) { // κ°€λ‘œμ€„ 놓을 수 μžˆλŠ”μ§€ 확인 + int cr = -1, cc = -1, cnt = 0; + for (int j = 0; j < 9; j++) { + if (board[i][j] == 0 && !row[i][num] && !col[j][num] && !box[boxIdx(i, j)][num]) { + cr = i; + cc = j; + cnt++; + } + } + if (cnt == 1) { + placeNumber(cr, cc, num); + flag = true; + } + } + + for (int j = 0; j < 9; j++) { // μ„Έλ‘œμ€„ 놓을 수 μžˆλŠ”μ§€ 확인 + int cr = -1, cc = -1, cnt = 0; + for (int i = 0; i < 9; i++) { + if (board[i][j] == 0 && !row[i][num] && !col[j][num] && !box[boxIdx(i, j)][num]) { + cr = i; + cc = j; + cnt++; + } + } + if (cnt == 1) { + placeNumber(cr, cc, num); + flag = true; + } + } + + for (int idx = 0; idx < 9; idx++) { // λ°•μŠ€ 놓을 수 μžˆλŠ”μ§€ 확인 + int cr = -1, cc = -1, cnt = 0; + int sr = (idx / 3) * 3, sc = (idx % 3) * 3; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + int r = sr + i; + int c = sc + j; + if (board[r][c] == 0 && !row[r][num] && !col[c][num] && !box[idx][num]) { + cr = r; + cc = c; + cnt++; + } + } + } + if (cnt == 1) { + placeNumber(cr, cc, num); + flag = true; + } + } + return flag; + } + + private static void placeNumber(int r, int c, int num) { + board[r][c] = num; + row[r][num] = true; + col[c][num] = true; + box[boxIdx(r, c)][num] = true; + } + + private static int boxIdx(int i, int j) { + return (i / 3) * 3 + j / 3; + } + + private static void printBoard() { + StringBuilder sb = new StringBuilder(); + for (int[] row : board) { + for (int c : row) { + sb.append(c == 0 ? "." : c); + } + sb.append("\n"); + } + System.out.print(sb); + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + for (int i = 0; i < 9; i++) { + String line = br.readLine(); + for (int j = 0; j < 9; j++) { + int num = line.charAt(j) == '.' ? 0 : line.charAt(j) - '0'; + board[i][j] = num; + if (num != 0) { + if (row[i][num] || col[j][num] || box[boxIdx(i, j)][num]) { // μž…λ ₯값이 잘λͺ»λμ„ 경우 μ—λŸ¬ + System.out.println("ERROR"); + return; + } + row[i][num] = true; + col[j][num] = true; + box[boxIdx(i, j)][num] = true; + } + } + } + + boolean doTry = false; // 첫 μ‹œλ„ 체크 λ³€μˆ˜ + boolean updated = true; // 숫자 적은거 μžˆλŠ”μ§€ 체크 + while (updated) { + updated = false; + for (int num = 1; num <= 9; num++) { + boolean res = crossHatching(num); + updated |= res; + doTry |= res; + } + } + + if (!doTry){ // μ•„μ˜ˆ μ‹œλ„μ‘°μ°¨ λͺ»ν•  경우 μ—λŸ¬ + System.out.println("ERROR"); + return; + } + + printBoard(); + } +} \ No newline at end of file

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /