From a7cf66faadfe09d2c95567983d8a45b00d29a425 Mon Sep 17 00:00:00 2001 From: icegosimperson Date: 2024年12月10日 11:30:50 +0900 Subject: [PATCH 1/8] =?UTF-8?q?=EC=9D=B4=ED=98=9C=EC=9B=90:=20[BOJ]=202294?= =?UTF-8?q?4=20=EC=A3=BD=EC=9D=8C=EC=9D=98=20=EB=B9=84=5F241210?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/20001-25000353円262円210円/HW_22944.java" | 99 +++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 "BOJ/20001-25000353円262円210円/HW_22944.java" diff --git "a/BOJ/20001-25000353円262円210円/HW_22944.java" "b/BOJ/20001-25000353円262円210円/HW_22944.java" new file mode 100644 index 00000000..24a980e8 --- /dev/null +++ "b/BOJ/20001-25000353円262円210円/HW_22944.java" @@ -0,0 +1,99 @@ +import java.io.*; +import java.util.*; + +public class HW_22944 { + static int N, H, D; + static char[][] board; + static int[][] check; + static int[] dx = {-1, 1, 0, 0}; + static int[] dy = {0, 0, -1, 1}; + + static class Node { + int x, y, h, d, m; + + public Node(int x, int y, int h, int d, int m) { + this.x = x; + this.y = y; + this.h = h; // 현재 체력 + this.d = d; // 우산 내구도 + this.m = m; // 이동 횟수 + } + } + + 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()); + H = Integer.parseInt(st.nextToken()); + D = Integer.parseInt(st.nextToken()); + + board = new char[N][N]; + check = new int[N][N]; + + int startX = 0, startY = 0; + for (int i = 0; i < N; i++) { + String line = br.readLine(); + for (int j = 0; j < N; j++) { + board[i][j] = line.charAt(j); + if (board[i][j] == 'S') { + startX = i; + startY = j; + } + } + } + + for (int i = 0; i < N; i++) { + Arrays.fill(check[i], -1); + } + + int result = bfs(startX, startY); + System.out.println(result); + } + + public static int bfs(int sx, int sy) { + Queue queue = new LinkedList(); + queue.add(new Node(sx, sy, H, 0, 0)); // 시작점 추가 + check[sx][sy] = H; // 시작점 방문 처리 + + while (!queue.isEmpty()) { + Node cur = queue.poll(); + + for (int i = 0; i < 4; i++) { + int newH = cur.h, newD = cur.d, newM = cur.m; + int nx = cur.x + dx[i]; + int ny = cur.y + dy[i]; + + + if (!isValid(nx, ny)) + continue; + + if (board[nx][ny] == 'E') { // 안전지대에 도달하면 이동 횟수 반환 + return newM + 1; + } + + if (board[nx][ny] == 'U') + newD = D; + + if (newD> 0) { + newD--; + } else { + newH--; + } + + if (newH == 0) + continue; + + if (check[nx][ny] < newH + newD) { + check[nx][ny] = newH + newD; + queue.add(new Node(nx, ny, newH, newD, newM + 1)); + } + } + } + return -1; // 안전지대에 도달하지 못한 경우 + } + + public static boolean isValid(int nx, int ny) { + return 0<= nx && nx < N && 0 <=ny && ny < N; + } +} From d4180e438fcacef6c6fa47872556c3d99ef55647 Mon Sep 17 00:00:00 2001 From: icegosimperson Date: 2024年12月10日 11:32:21 +0900 Subject: [PATCH 2/8] =?UTF-8?q?=EC=9D=B4=ED=98=9C=EC=9B=90:=20[SQL]=20Stud?= =?UTF-8?q?ents=20and=20Examinations=5F241210?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HW_Students and Examinations.sql" | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 "SQL/14354円243円274円354円260円250円/HW_Students and Examinations.sql" diff --git "a/SQL/14354円243円274円354円260円250円/HW_Students and Examinations.sql" "b/SQL/14354円243円274円354円260円250円/HW_Students and Examinations.sql" new file mode 100644 index 00000000..d1e680d3 --- /dev/null +++ "b/SQL/14354円243円274円354円260円250円/HW_Students and Examinations.sql" @@ -0,0 +1,8 @@ +SELECT s.student_id, s.student_name, sb.subject_name, COUNT(e.subject_name) AS attended_exams +FROM Students s + CROSS JOIN Subjects sb + LEFT JOIN Examinations e + ON s.student_id = e.student_id + AND sb.subject_name = e.subject_name +GROUP BY s.student_id, s.student_name, sb.subject_name +ORDER BY s.student_id, s.student_name, sb.subject_name; \ No newline at end of file From 703be679cd1c90e353cd71472c0590cc05060a42 Mon Sep 17 00:00:00 2001 From: icegosimperson Date: 2024年12月11日 14:16:34 +0900 Subject: [PATCH 3/8] =?UTF-8?q?=EC=9D=B4=ED=98=9C=EC=9B=90:=20[BOJ]=202018?= =?UTF-8?q?1=20=EA=BF=88=ED=8B=80=EA=BF=88=ED=8B=80=20=ED=98=B8=EC=84=9D?= =?UTF-8?q?=20=EC=95=A0=EB=B2=8C=EB=A0=88=20-=20=ED=9A=A8=EC=9C=A8?= =?UTF-8?q?=EC=84=B1=5F241211?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/20001-25000353円262円210円/HW_20181.java" | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "BOJ/20001-25000353円262円210円/HW_20181.java" diff --git "a/BOJ/20001-25000353円262円210円/HW_20181.java" "b/BOJ/20001-25000353円262円210円/HW_20181.java" new file mode 100644 index 00000000..149a8340 --- /dev/null +++ "b/BOJ/20001-25000353円262円210円/HW_20181.java" @@ -0,0 +1,36 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class HW_20181 { + 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 K = Integer.parseInt(st.nextToken()); // 최소 만족도 + int[] arr = new int[N]; + long[] dp = new long[N+1]; // dp[i] : i번쨰 먹이까지의 최대 탈피 에너지 + + st = new StringTokenizer(br.readLine()); + for(int i=0; i Date: 2024年12月12日 12:41:51 +0900 Subject: [PATCH 4/8] =?UTF-8?q?=EC=9D=B4=ED=98=9C=EC=9B=90:=20[BOJ]=202029?= =?UTF-8?q?1=20=ED=8C=8C=EC=9D=BC=20=EC=A0=95=EB=A6=AC=5F241211?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/20001-25000353円262円210円/HW_20291.java" | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "BOJ/20001-25000353円262円210円/HW_20291.java" diff --git "a/BOJ/20001-25000353円262円210円/HW_20291.java" "b/BOJ/20001-25000353円262円210円/HW_20291.java" new file mode 100644 index 00000000..e40bdefa --- /dev/null +++ "b/BOJ/20001-25000353円262円210円/HW_20291.java" @@ -0,0 +1,23 @@ +import java.io.*; +import java.util.*; + +public class HW_20291 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + + TreeMap words = new TreeMap(); + + for(int i=0; i entry : words.entrySet()) { + System.out.println(entry.getKey() + " " + entry.getValue()); + } + + } +} \ No newline at end of file From c55a1be0a154e97b371b4052703fe108e31746c4 Mon Sep 17 00:00:00 2001 From: icegosimperson Date: 2024年12月12日 12:42:46 +0900 Subject: [PATCH 5/8] =?UTF-8?q?=EC=9D=B4=ED=98=9C=EC=9B=90:=20[SQL]=20Odd?= =?UTF-8?q?=20and=20Even=20Transactions=5F241212?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HW_Odd and Even Transactions.sql" | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 "SQL/14354円243円274円354円260円250円/HW_Odd and Even Transactions.sql" diff --git "a/SQL/14354円243円274円354円260円250円/HW_Odd and Even Transactions.sql" "b/SQL/14354円243円274円354円260円250円/HW_Odd and Even Transactions.sql" new file mode 100644 index 00000000..3cc3ad05 --- /dev/null +++ "b/SQL/14354円243円274円354円260円250円/HW_Odd and Even Transactions.sql" @@ -0,0 +1,7 @@ +SELECT + transaction_date, + SUM(CASE WHEN amount % 2 = 1 THEN amount ELSE 0 END) AS odd_sum, + SUM(CASE WHEN amount % 2 = 0 THEN amount ELSE 0 END) AS even_sum +FROM transactions +GROUP BY transaction_date +ORDER BY transaction_date; \ No newline at end of file From 2704a2c357ac8c5e6d12222dc6807080ca66bfe6 Mon Sep 17 00:00:00 2001 From: icegosimperson Date: 2024年12月12日 23:21:38 +0900 Subject: [PATCH 6/8] =?UTF-8?q?=EC=9D=B4=ED=98=9C=EC=9B=90:=20[PG]=2034021?= =?UTF-8?q?1=20=EC=B6=A9=EB=8F=8C=EC=9C=84=ED=97=98=20=EC=B0=BE=EA=B8=B0?= =?UTF-8?q?=5F241212?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level2/HW_340211.java | 67 +++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Programmers/Level2/HW_340211.java diff --git a/Programmers/Level2/HW_340211.java b/Programmers/Level2/HW_340211.java new file mode 100644 index 00000000..1e6f67b6 --- /dev/null +++ b/Programmers/Level2/HW_340211.java @@ -0,0 +1,67 @@ +import java.util.HashMap; +import java.util.Map; + +class HW_340211 { + Map timePos; // 시간, 위치별 충돌 횟수 관리 + Map m; // 포인트 번호별 좌표 관리 (key 포인트 번호, value [r,c]) + int answer= 0; + + public int solution(int[][] points, int[][] routes) { + m = new HashMap(); + timePos = new HashMap(); + + for(int i = 0; i targetX) + startX--; + else if(startY < targetY) + startY++; + else if(startY> targetY) + startY--; + + time++; + last[0] = startX; + last[1] = startY; + } + } + String key = time+"-"+last[0]+"-"+last[1]; + timePos.put(key, timePos.getOrDefault(key, 0) + 1); + + if(timePos.get(key) == 2) { // 충돌 횟수++ + answer++; + } + } +} \ No newline at end of file From 06a8d25ce888eb751923af5eeb114f7d783775a7 Mon Sep 17 00:00:00 2001 From: icegosimperson Date: 2024年12月13日 10:23:18 +0900 Subject: [PATCH 7/8] =?UTF-8?q?=EC=9D=B4=ED=98=9C=EC=9B=90:=20[CT]=20?= =?UTF-8?q?=EC=83=89=EA=B9=94=20=ED=8F=AD=ED=83=84=5F241209?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352271円224円_355円217円255円355円203円204円.java" | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 "CodeTree/2021-2022353円205円204円/HW_354円203円211円352円271円224円_355円217円255円355円203円204円.java" diff --git "a/CodeTree/2021-2022353円205円204円/HW_354円203円211円352円271円224円_355円217円255円355円203円204円.java" "b/CodeTree/2021-2022353円205円204円/HW_354円203円211円352円271円224円_355円217円255円355円203円204円.java" new file mode 100644 index 00000000..18bda886 --- /dev/null +++ "b/CodeTree/2021-2022353円205円204円/HW_354円203円211円352円271円224円_355円217円255円355円203円204円.java" @@ -0,0 +1,179 @@ +import java.io.*; +import java.util.*; + +public class HW_색깔_폭탄 { + static int n, m; + static int[][] board; + static int score = 0; + static int[] dx = {-1,1,0,0}; + static int[] dy = {0,0,-1,1}; + + static class Bomb { + int size; + int redCount; + int stdX; + int stdY; + List blocks; // 폭탄 묶음 내 좌표 + + Bomb(int size, int redCount, int stdX, int stdY, List blocks) { + this.size = size; + this.redCount = redCount; + this.stdX = stdX; + this.stdY = stdY; + this.blocks = blocks; + } + } + + 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()); + board = new int[n][n]; + + for (int i=0; i candidates = new ArrayList(); + + for (int i=0; i { + if (a.size != b.size) // 1. size 내림차순 + return b.size - a.size; + if (a.redCount != b.redCount) // 2. redCount 오름차순 + return a.redCount - b.redCount; + if (a.stdX != b.stdX) // 3. 기준 행 내림차순 + return b.stdX - a.stdX; + return a.stdY - b.stdY; // 4. 기준 열 오름차순 + }); + + return candidates.get(0); + } + + static Bomb bfs(int sx, int sy, int color) { + boolean[][] visited = new boolean[n][n]; + Queue q = new LinkedList(); + q.offer(new int[]{sx, sy}); + visited[sx][sy] = true; + + List group = new ArrayList(); + group.add(new int[]{sx, sy}); + int redCount = (board[sx][sy] == 0) ? 1 : 0; + + while(!q.isEmpty()){ + int[] cur = q.poll(); + int x=cur[0], y=cur[1]; + + for (int k=0; k<4; k++){ + int nx = x + dx[k]; + int ny = y + dy[k]; + if (!isValid(nx, ny)) { + continue; + } + if (board[nx][ny] == -1) { // 검은 돌 제외 + continue; + } + if (!visited[nx][ny]) { + if (board[nx][ny] == color || board[nx][ny] == 0) { + visited[nx][ny] = true; + q.offer(new int[]{nx,ny}); + group.add(new int[]{nx,ny}); + if (board[nx][ny] == 0) { + redCount++; + } + } + } + } + } + + if (group.size()<2) return null; + + + int targetX=-1; + int targetY=-1; + for (int i=0; i targetX || (gx==targetX && (targetY==-1 || gy < targetY))) { + targetX = gx; + targetY = gy; + } + } + } + return new Bomb(group.size(), redCount, targetX, targetY, group); + } + + static void remove(Bomb b) { + for (int i=0; i=0; x--){ + if (board[x][y]> -1) { + int nx = x; + while(true) { + int down = nx+1; + if (down>=n) break; + if (board[down][y]!=-2) break; + board[down][y]=board[nx][y]; + board[nx][y]=-2; + nx=down; + } + } + } + } + } + static int[][] rotate(int[][] arr) { + int[][] newBoard = new int[n][n]; + for (int x=0; x Date: 2024年12月14日 08:35:26 +0900 Subject: [PATCH 8/8] =?UTF-8?q?=EC=9D=B4=ED=98=9C=EC=9B=90:=20[PG]=20?= =?UTF-8?q?=EB=93=B1=EC=82=B0=EC=BD=94=EC=8A=A4=20=EC=A0=95=ED=95=98?= =?UTF-8?q?=EA=B8=B0=5F241213?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level3/HW_118669.java | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Programmers/Level3/HW_118669.java diff --git a/Programmers/Level3/HW_118669.java b/Programmers/Level3/HW_118669.java new file mode 100644 index 00000000..ea410236 --- /dev/null +++ b/Programmers/Level3/HW_118669.java @@ -0,0 +1,79 @@ +import java.util.*; + +class HW_118669 { + public int[] solution(int n, int[][] paths, int[] gates, int[] summits) { + List[] graph = new ArrayList[n + 1]; + for (int i = 0; i <= n; i++) { + graph[i] = new ArrayList(); + } + for (int i = 0; i < paths.length; i++) { + int a = paths[i][0]; + int b = paths[i][1]; + int w = paths[i][2]; + graph[a].add(new int[]{b, w}); // 양방향 + graph[b].add(new int[]{a, w}); + } + + Set gateSet = new HashSet(); // 출입구 + Set summitSet = new HashSet(); // 산봉우리 + for (int i = 0; i < gates.length; i++) { + gateSet.add(gates[i]); + } + for (int i = 0; i < summits.length; i++) { + summitSet.add(summits[i]); + } + + int[] intensity = new int[n + 1]; + for (int i = 0; i <= n; i++) { + intensity[i] = Integer.MAX_VALUE; + } + + PriorityQueue pq = new PriorityQueue((a, b) -> a[1] - b[1]); + + for (int i = 0; i < gates.length; i++) { // 모든 출입구를 시작점으로 초기화 + pq.offer(new int[]{gates[i], 0}); + intensity[gates[i]] = 0; + } + + while (!pq.isEmpty()) { // 다익스트라 + int[] cur = pq.poll(); + int now = cur[0]; + int curIntensity = cur[1]; + + if (intensity[now] < curIntensity) { // 현재 intensity가 이미 최솟값보다 크면 무시 + continue; + } + + for (int i = 0; i < graph[now].size(); i++) { // 현재 지점에서 이동 가능한 모든 경로 탐색 + int[] next = graph[now].get(i); + int nextNode = next[0]; + int weight = next[1]; + + if (gateSet.contains(nextNode)) { // 산봉우리는 거쳐갈 수 없음 + continue; + } + + int newIntensity = Math.max(curIntensity, weight); // 현재 경로에서의 최대 intensity 갱신 + + if (newIntensity < intensity[nextNode]) { // 더 작은 intensity로 업데이트 + intensity[nextNode] = newIntensity; + pq.offer(new int[]{nextNode, newIntensity}); + } + } + } + + int minIntensity = Integer.MAX_VALUE; + int bestSummit = -1; + + Arrays.sort(summits); // 산봉우리 번호가 낮은 것을 우선 처리하기 위함 + for (int i = 0; i < summits.length; i++) { + int summit = summits[i]; + if (intensity[summit] < minIntensity) { + minIntensity = intensity[summit]; + bestSummit = summit; + } + } + + return new int[]{bestSummit, minIntensity}; + } +} \ No newline at end of file

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