-
Notifications
You must be signed in to change notification settings - Fork 4
[25주차] 배수빈 #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
[25주차] 배수빈 #338
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
BOJ/10001-15000번/SB_12784.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_12784 { | ||
static List<List<Node>> adj; | ||
static boolean[] parents; | ||
|
||
private static int dfs(int node) { | ||
int cnt = 0; | ||
parents[node] = true; | ||
|
||
for (Node nxt : adj.get(node)) { | ||
if (parents[nxt.idx]) continue; // 부모는 패쓰 | ||
cnt += Math.min(nxt.val, dfs(nxt.idx)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 최솟값을 이렇게 갱신해도되는군요 |
||
} | ||
|
||
if (cnt==0 && adj.get(node).size()==1) return adj.get(node).get(0).val; // 리프노드면 부모와 이어진 값 반환 | ||
return cnt; | ||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
int T = Integer.parseInt(br.readLine()); | ||
while (T-- > 0) { | ||
st = new StringTokenizer(br.readLine()); | ||
int N = Integer.parseInt(st.nextToken()); | ||
int M = Integer.parseInt(st.nextToken()); | ||
if (N==1) { | ||
sb.append(0).append("\n"); | ||
continue; | ||
} | ||
adj = new ArrayList<>(); | ||
for (int i = 0; i <= N; i++) { | ||
adj.add(new ArrayList<>()); | ||
} | ||
parents = new boolean[N + 1]; | ||
for (int i = 0; i < M; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int u = Integer.parseInt(st.nextToken()); | ||
int v = Integer.parseInt(st.nextToken()); | ||
int c = Integer.parseInt(st.nextToken()); | ||
adj.get(u).add(new Node(v, c)); | ||
adj.get(v).add(new Node(u, c)); | ||
} | ||
sb.append(dfs(1)).append("\n"); | ||
} | ||
|
||
// 1과 연결된 부모 노드 구하기 (재귀) | ||
// 해당 노드와 연결된 리프노드들에서 해당 노드로 오는 값의 합, 해당 노드에서 부모노드까지 합 중 최소값 선택 | ||
System.out.println(sb); | ||
} | ||
|
||
private static class Node{ | ||
int idx, val; | ||
|
||
public Node(int idx, int val) { | ||
this.idx = idx; | ||
this.val = val; | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
BOJ/5001-10000번/SB_9944.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_9944 { | ||
static int N, M; | ||
static char[][] board; | ||
static int mn; | ||
static final int INF = Integer.MAX_VALUE; | ||
static int[] dx = {-1, 1, 0, 0}; | ||
static int[] dy = {0, 0, -1, 1}; | ||
|
||
private static boolean isAllVisited(boolean[][] visited) { | ||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < M; j++) { | ||
if (!visited[i][j]) return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private static void dfs(int x, int y, int cnt, boolean[][] visited) { | ||
if (cnt >= mn) return; // 가지 치기 | ||
|
||
boolean canMove = false; | ||
for (int i = 0; i < 4; i++) { | ||
int nx = x + dx[i]; | ||
int ny = y + dy[i]; | ||
if (!isValid(nx, ny) || visited[nx][ny]) continue; | ||
canMove = true; | ||
|
||
while (isValid(nx, ny) && !visited[nx][ny]) { | ||
visited[nx][ny] = true; | ||
nx += dx[i]; | ||
ny += dy[i]; | ||
} | ||
|
||
nx -= dx[i]; // 위에서 한 칸 삐져나오니까 한칸 뒤로가기 | ||
ny -= dy[i]; | ||
|
||
dfs(nx, ny, cnt + 1, visited); // 한 방향 당 cnt++ | ||
|
||
while (nx != x || ny != y) { // 처음위치까지 이동 | ||
visited[nx][ny] = false; | ||
nx -= dx[i]; | ||
ny -= dy[i]; | ||
} | ||
} | ||
|
||
if (!canMove && isAllVisited(visited)) { // 더이상 움직일 수 없고 모든 칸 방문 시 mn 업데이트 | ||
mn = Math.min(mn, cnt); | ||
} | ||
} | ||
|
||
private static boolean isValid(int x, int y) { | ||
return 0 <= x && x < N && 0 <= y && y < M; | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
String line; | ||
int turn = 1; | ||
while ((line = br.readLine()) != null && !line.isEmpty()) { | ||
st = new StringTokenizer(line); | ||
N = Integer.parseInt(st.nextToken()); | ||
M = Integer.parseInt(st.nextToken()); | ||
|
||
board = new char[N][M]; | ||
boolean[][] visited = new boolean[N][M]; | ||
mn = INF; | ||
|
||
for (int i = 0; i < N; i++) { | ||
line = br.readLine(); | ||
for (int j = 0; j < M; j++) { | ||
board[i][j] = line.charAt(j); | ||
if (board[i][j] == '*') visited[i][j] = true; | ||
} | ||
} | ||
|
||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < M; j++) { | ||
if (board[i][j] == '*' || visited[i][j]) continue; | ||
visited[i][j] = true; | ||
dfs(i, j, 0, visited); | ||
visited[i][j] = false; | ||
} | ||
} | ||
sb.append("Case ").append(turn++).append(": ").append(mn == INF ? -1 : mn).append("\n"); | ||
} | ||
|
||
System.out.println(sb); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
Programmers/Level2/SB_389480.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import java.util.*; | ||
|
||
class SB_389480 { | ||
public int solution(int[][] info, int n, int m) { | ||
int INF = 1000; | ||
int idx = info.length; | ||
|
||
int[][] dp = new int[idx+1][m]; // dp[i][j]=k, i만큼 물건을 훔칠때 B의 흔적개수가 j, 이때 A의 최소 흔적 개수 | ||
for(int i=0; i<=idx; i++) { | ||
Arrays.fill(dp[i], INF); | ||
} | ||
|
||
dp[0][0] = 0; | ||
|
||
for(int i=1; i<=idx; i++){ | ||
int a = info[i-1][0]; // 현재 물건을 훔칠때 a,b의 각 흔적 | ||
int b = info[i-1][1]; | ||
for(int j=0; j<m; j++){ | ||
dp[i][j] = Math.min(dp[i][j], dp[i-1][j]+a); | ||
if(j+b < m){ | ||
dp[i][j+b] = Math.min(dp[i][j+b], dp[i-1][j]); | ||
} | ||
} | ||
} | ||
|
||
int mn = INF; | ||
for(int j=0; j<m; j++){ | ||
mn = Math.min(mn, dp[idx][j]); | ||
} | ||
return mn >= n ? -1 : mn; | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
SQL/25주차/SB_입양시각구하기(2).sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.