-
Notifications
You must be signed in to change notification settings - Fork 4
[19주차] 배수빈 #262
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
Merged
[19주차] 배수빈 #262
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
889944d
배수빈: [BOJ] 1938 통나무 옮기기_250120
baexxbin 2a6000e
배수빈: [BOJ] 13334 철로_250122
baexxbin 8f5d869
배수빈: [BOJ] 1405 미친 로봇_250123
baexxbin 46fee42
배수빈: [SQL] Immediate Food Delivery II
baexxbin 58179f4
배수빈: [BOJ] 1256 사전_250124
baexxbin 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
68 changes: 68 additions & 0 deletions
BOJ/1000-5000번/SB_1256.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,68 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_1256 { | ||
static int N, M, K; | ||
static long[][] dp; | ||
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()); | ||
M = Integer.parseInt(st.nextToken()); | ||
K = Integer.parseInt(st.nextToken()); | ||
|
||
dp = new long[N+1][M+1]; | ||
|
||
// dp배열 만들기 | ||
dp[0][0] = 1; // 아무것도 못만드는 경우 1개 | ||
for (int i = 1; i <= N; i++) { // a만으로 이루어진 경우 | ||
dp[i][0] = 1; | ||
} | ||
for (int j = 1; j <= M; j++) { // z만으로 이루어진 경우 | ||
dp[0][j] = 1; | ||
} | ||
|
||
for (int i = 1; i <= N; i++) { | ||
for (int j = 1; j <= M; j++) { | ||
dp[i][j] = Math.min(dp[i - 1][j] + dp[i][j - 1], K); // a를 앞에 추가해서 만들기 + z를 앞에 추가해서 만들기 | ||
} | ||
} | ||
|
||
// K가 범위 벗어나면 -1 | ||
if (dp[N][M] < K) { | ||
System.out.println(-1); | ||
return; | ||
} | ||
|
||
// 사전순으로 문자열 만들기 | ||
while (N > 0 && M > 0) { | ||
long tmp = dp[N - 1][M]; // a로 시작하는 문자열의 개수 | ||
if (K <= tmp) { // K가 tmp(a로 시작하는 범위의 개수)에 속할경우 | ||
N -= 1; // 현재 tmp에서 N=-1해서 다음 경우 살피기 (현재 자리값 고정, 다음 자리 확인) | ||
sb.append('a'); // a로 시작하기에 a붙이기 | ||
} else { // K가 tmp보다 클 경우 z를 시작으로하는 범위에서 살피기 | ||
M -= 1; // M=-1해서 다음 경우 살피기 | ||
K -= tmp; // K에서 제외된 tmp값 빼주기 | ||
sb.append('z'); // z로 시작하기에 z붙이기 | ||
} | ||
} | ||
|
||
// 남은 문자 처리 | ||
while (N > 0) { | ||
sb.append('a'); | ||
N--; | ||
} | ||
|
||
while (M > 0) { | ||
sb.append('z'); | ||
M--; | ||
} | ||
|
||
System.out.println(sb); | ||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
BOJ/1000-5000번/SB_1405.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,44 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_1405 { | ||
static int N; | ||
static int[] dx = {0, 0, 1, -1}; // 동, 서, 남, 북 | ||
static int[] dy = {1, -1, 0, 0}; | ||
static double[] prob = new double[4]; | ||
static boolean[][] visited = new boolean[30][30]; | ||
static double ans = 0; | ||
|
||
private static void dfs(int x, int y, int depth, double total) { | ||
if (depth==N) { | ||
ans += total; | ||
return; | ||
} | ||
|
||
for (int i = 0; i < 4; i++) { | ||
int nx = x + dx[i]; | ||
int ny = y + dy[i]; | ||
if (!visited[nx][ny]){ // 방문하지 않은 곳이라면 | ||
visited[nx][ny] = true; | ||
dfs(nx, ny, depth+1, total*prob[i]); | ||
visited[nx][ny] = false; | ||
} | ||
} | ||
} | ||
|
||
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()); | ||
for (int i = 0; i < 4; i++) { | ||
prob[i] = Integer.parseInt(st.nextToken())*0.01; // 확률로 표현 | ||
} | ||
|
||
visited[15][15] = true; | ||
dfs(15, 15, 0, 1); | ||
System.out.println(ans); | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
BOJ/1000-5000번/SB_1938.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,140 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class SB_1938 { | ||
static int N; | ||
static int[][] board; | ||
static int[][][] visited; | ||
static Node target; | ||
static int[] dx = {-1, 1, 0, 0, 0}; | ||
static int[] dy = {0, 0, -1, 1, 0}; | ||
|
||
private static int bfs(Node start) { | ||
Queue<Node> que = new ArrayDeque<>(); | ||
que.offer(start); | ||
visited[start.x][start.y][start.ty] = 0; | ||
|
||
while (!que.isEmpty()) { | ||
Node cur = que.poll(); | ||
if (cur.x==target.x && cur.y== target.y && cur.ty== target.ty) return visited[cur.x][cur.y][cur.ty]; | ||
|
||
for (int i = 0; i < 5; i++) { | ||
int nx = cur.x + dx[i]; | ||
int ny = cur.y + dy[i]; | ||
if (!isValid(nx, ny) || board[nx][ny]==1) continue; // 중심좌표가 범위 벗어나면 패쓰 | ||
|
||
if (i==4) { // 회전할때 경우 | ||
int nt = cur.ty ^ 1; | ||
if(canTurn(nx, ny, nt) && visited[nx][ny][nt]==-1) { | ||
que.offer(new Node(nx, ny, nt)); | ||
visited[nx][ny][nt] = visited[cur.x][cur.y][cur.ty] + 1; | ||
} | ||
continue; | ||
} | ||
|
||
// 상하좌우로 움직인 nx,ny 값에 대해 가로,세로일때 각 양날개가 가능한지 체크 | ||
if (cur.ty == 0 && canWingRow(nx, ny) && visited[nx][ny][cur.ty]==-1) { | ||
que.offer(new Node(nx, ny, cur.ty)); | ||
visited[nx][ny][cur.ty] = visited[cur.x][cur.y][cur.ty] + 1; | ||
} else if (cur.ty == 1 && canWingCol(nx, ny) && visited[nx][ny][cur.ty]==-1) { | ||
que.offer(new Node(nx, ny, cur.ty)); | ||
visited[nx][ny][cur.ty] = visited[cur.x][cur.y][cur.ty] + 1; | ||
} | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
private static boolean canWingRow(int r, int c) { // 가로일때 날개 유효한지 | ||
return isValid(r, c-1) && isValid(r, c+1) && board[r][c - 1] == 0 && board[r][c + 1] == 0; | ||
} | ||
|
||
private static boolean canWingCol(int r, int c) { // 세로일때 날개 유효한지 | ||
return isValid(r-1, c) && isValid(r+1, c) && board[r-1][c] == 0 && board[r+1][c] == 0; | ||
} | ||
|
||
private static boolean canTurn(int r, int c, int t) { | ||
for (int i = r - 1; i <= r + 1; i++) { | ||
for (int j = c - 1; j <= c + 1; j++) { | ||
if (!isValid(i, j) || board[i][j]==1) return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private static boolean isValid(int x, int y) { // 좌표 유효성 검사 | ||
return 0<=x && x<N && 0<=y && y<N; | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
N = Integer.parseInt(br.readLine()); | ||
board = new int[N][N]; | ||
visited = new int[N][N][2]; | ||
|
||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < N; j++) { | ||
for (int k = 0; k < 2; k++) { | ||
visited[i][j][k] = -1; | ||
} | ||
} | ||
} | ||
|
||
List<int[]> b = new ArrayList<>(); | ||
List<int[]> e = new ArrayList<>(); | ||
for (int i=0; i<N; i++){ | ||
String line = br.readLine(); | ||
for (int j = 0; j < N; j++) { | ||
char c = line.charAt(j); | ||
if (Character.isDigit(c)) { | ||
board[i][j] = c - '0'; | ||
continue; | ||
} | ||
if (c=='B') b.add(new int[]{i, j}); | ||
else if (c=='E') e.add(new int[]{i, j}); | ||
board[i][j] = 0; | ||
} | ||
} | ||
|
||
Collections.sort(b, (o1, o2) -> { | ||
if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]); | ||
return Integer.compare(o1[1], o2[1]); | ||
}); | ||
|
||
Collections.sort(e, (o1, o2) -> { | ||
if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]); | ||
return Integer.compare(o1[1], o2[1]); | ||
}); | ||
|
||
// 처음 중심 좌표 및 형태 | ||
int tb = (b.get(0)[0] == b.get(1)[0]) ? 0 : 1; // 가로(0), 세로(1) | ||
int te = (e.get(0)[0] == e.get(1)[0]) ? 0 : 1; | ||
Node start = new Node(b.get(1)[0], b.get(1)[1], tb); // 중간값이 중심값 | ||
target = new Node(e.get(1)[0], e.get(1)[1], te); | ||
|
||
System.out.println(bfs(start)); | ||
} | ||
|
||
static class Node{ | ||
int x, y, ty; | ||
|
||
public Node(int x, int y, int ty) { | ||
this.x = x; | ||
this.y = y; | ||
this.ty = ty; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Node{" + | ||
"x=" + x + | ||
", y=" + y + | ||
", ty=" + ty + | ||
'}'; | ||
} | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
BOJ/10001-15000번/SB_13334.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,52 @@ | ||
package PriorityQueue; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.PriorityQueue; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_13334 { | ||
static int N, d; | ||
static PriorityQueue<Node> pq = new PriorityQueue<>(); | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
N = Integer.parseInt(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int s = Integer.parseInt(st.nextToken()); | ||
int e = Integer.parseInt(st.nextToken()); | ||
pq.offer(new Node(Math.min(s, e), Math.max(s, e))); // 집과 사무실 중 작은게 시작, 큰게 끝 | ||
} | ||
d = Integer.parseInt(br.readLine()); | ||
|
||
PriorityQueue<Integer> pre = new PriorityQueue<>(); // 이전 사람들의 정보를 저장하는 우선순위 큐 | ||
int mx = 0; | ||
while (!pq.isEmpty()) { | ||
Node cur = pq.poll(); | ||
int start = cur.e - d; // 철로의 시작 지점 | ||
pre.offer(cur.s); // 현재 노드의 시작지점을 pre큐에 넣어주기 | ||
while (!pre.isEmpty() && pre.peek() < start) { // 이전 사람들이 현재 철로에 속하지 못하면 빼주기 | ||
pre.poll(); | ||
} | ||
mx = Math.max(mx, pre.size()); | ||
} | ||
|
||
System.out.println(mx); | ||
} | ||
|
||
static class Node implements Comparable<Node>{ | ||
int s, e; | ||
|
||
public Node(int s, int e) { | ||
this.s = s; | ||
this.e = e; | ||
} | ||
@Override | ||
public int compareTo(Node o) { | ||
if (this.e-o.e!=0) return this.e - o.e; | ||
return this.s-o.s; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
SQL/19주차/SB_Immediate Food Delivery II.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,7 @@ | ||
SELECT ROUND(AVG(order_date = customer_pref_delivery_date)*100,2) as immediate_percentage | ||
FROM Delivery | ||
WHERE (customer_id, order_date) in ( | ||
SELECT customer_id, min(order_date) | ||
FROM Delivery | ||
GROUP BY customer_id | ||
) |
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.