Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e32fde

Browse files
Merge pull request #262 from GreatAlgorithm-Study/xubin
[19주차] 배수빈
2 parents ae6f049 + 58179f4 commit 5e32fde

File tree

5 files changed

+311
-0
lines changed

5 files changed

+311
-0
lines changed

‎BOJ/1000-5000번/SB_1256.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class SB_1256 {
7+
static int N, M, K;
8+
static long[][] dp;
9+
public static void main(String[] args) throws IOException {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
StringTokenizer st = new StringTokenizer(br.readLine());
12+
StringBuilder sb = new StringBuilder();
13+
14+
N = Integer.parseInt(st.nextToken());
15+
M = Integer.parseInt(st.nextToken());
16+
K = Integer.parseInt(st.nextToken());
17+
18+
dp = new long[N+1][M+1];
19+
20+
// dp배열 만들기
21+
dp[0][0] = 1; // 아무것도 못만드는 경우 1개
22+
for (int i = 1; i <= N; i++) { // a만으로 이루어진 경우
23+
dp[i][0] = 1;
24+
}
25+
for (int j = 1; j <= M; j++) { // z만으로 이루어진 경우
26+
dp[0][j] = 1;
27+
}
28+
29+
for (int i = 1; i <= N; i++) {
30+
for (int j = 1; j <= M; j++) {
31+
dp[i][j] = Math.min(dp[i - 1][j] + dp[i][j - 1], K); // a를 앞에 추가해서 만들기 + z를 앞에 추가해서 만들기
32+
}
33+
}
34+
35+
// K가 범위 벗어나면 -1
36+
if (dp[N][M] < K) {
37+
System.out.println(-1);
38+
return;
39+
}
40+
41+
// 사전순으로 문자열 만들기
42+
while (N > 0 && M > 0) {
43+
long tmp = dp[N - 1][M]; // a로 시작하는 문자열의 개수
44+
if (K <= tmp) { // K가 tmp(a로 시작하는 범위의 개수)에 속할경우
45+
N -= 1; // 현재 tmp에서 N=-1해서 다음 경우 살피기 (현재 자리값 고정, 다음 자리 확인)
46+
sb.append('a'); // a로 시작하기에 a붙이기
47+
} else { // K가 tmp보다 클 경우 z를 시작으로하는 범위에서 살피기
48+
M -= 1; // M=-1해서 다음 경우 살피기
49+
K -= tmp; // K에서 제외된 tmp값 빼주기
50+
sb.append('z'); // z로 시작하기에 z붙이기
51+
}
52+
}
53+
54+
// 남은 문자 처리
55+
while (N > 0) {
56+
sb.append('a');
57+
N--;
58+
}
59+
60+
while (M > 0) {
61+
sb.append('z');
62+
M--;
63+
}
64+
65+
System.out.println(sb);
66+
67+
}
68+
}

‎BOJ/1000-5000번/SB_1405.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class SB_1405 {
7+
static int N;
8+
static int[] dx = {0, 0, 1, -1}; // 동, 서, 남, 북
9+
static int[] dy = {1, -1, 0, 0};
10+
static double[] prob = new double[4];
11+
static boolean[][] visited = new boolean[30][30];
12+
static double ans = 0;
13+
14+
private static void dfs(int x, int y, int depth, double total) {
15+
if (depth==N) {
16+
ans += total;
17+
return;
18+
}
19+
20+
for (int i = 0; i < 4; i++) {
21+
int nx = x + dx[i];
22+
int ny = y + dy[i];
23+
if (!visited[nx][ny]){ // 방문하지 않은 곳이라면
24+
visited[nx][ny] = true;
25+
dfs(nx, ny, depth+1, total*prob[i]);
26+
visited[nx][ny] = false;
27+
}
28+
}
29+
}
30+
31+
public static void main(String[] args) throws IOException {
32+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
33+
StringTokenizer st = new StringTokenizer(br.readLine());
34+
35+
N = Integer.parseInt(st.nextToken());
36+
for (int i = 0; i < 4; i++) {
37+
prob[i] = Integer.parseInt(st.nextToken())*0.01; // 확률로 표현
38+
}
39+
40+
visited[15][15] = true;
41+
dfs(15, 15, 0, 1);
42+
System.out.println(ans);
43+
}
44+
}

‎BOJ/1000-5000번/SB_1938.java

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.*;
5+
6+
public class SB_1938 {
7+
static int N;
8+
static int[][] board;
9+
static int[][][] visited;
10+
static Node target;
11+
static int[] dx = {-1, 1, 0, 0, 0};
12+
static int[] dy = {0, 0, -1, 1, 0};
13+
14+
private static int bfs(Node start) {
15+
Queue<Node> que = new ArrayDeque<>();
16+
que.offer(start);
17+
visited[start.x][start.y][start.ty] = 0;
18+
19+
while (!que.isEmpty()) {
20+
Node cur = que.poll();
21+
if (cur.x==target.x && cur.y== target.y && cur.ty== target.ty) return visited[cur.x][cur.y][cur.ty];
22+
23+
for (int i = 0; i < 5; i++) {
24+
int nx = cur.x + dx[i];
25+
int ny = cur.y + dy[i];
26+
if (!isValid(nx, ny) || board[nx][ny]==1) continue; // 중심좌표가 범위 벗어나면 패쓰
27+
28+
if (i==4) { // 회전할때 경우
29+
int nt = cur.ty ^ 1;
30+
if(canTurn(nx, ny, nt) && visited[nx][ny][nt]==-1) {
31+
que.offer(new Node(nx, ny, nt));
32+
visited[nx][ny][nt] = visited[cur.x][cur.y][cur.ty] + 1;
33+
}
34+
continue;
35+
}
36+
37+
// 상하좌우로 움직인 nx,ny 값에 대해 가로,세로일때 각 양날개가 가능한지 체크
38+
if (cur.ty == 0 && canWingRow(nx, ny) && visited[nx][ny][cur.ty]==-1) {
39+
que.offer(new Node(nx, ny, cur.ty));
40+
visited[nx][ny][cur.ty] = visited[cur.x][cur.y][cur.ty] + 1;
41+
} else if (cur.ty == 1 && canWingCol(nx, ny) && visited[nx][ny][cur.ty]==-1) {
42+
que.offer(new Node(nx, ny, cur.ty));
43+
visited[nx][ny][cur.ty] = visited[cur.x][cur.y][cur.ty] + 1;
44+
}
45+
}
46+
}
47+
return 0;
48+
}
49+
50+
private static boolean canWingRow(int r, int c) { // 가로일때 날개 유효한지
51+
return isValid(r, c-1) && isValid(r, c+1) && board[r][c - 1] == 0 && board[r][c + 1] == 0;
52+
}
53+
54+
private static boolean canWingCol(int r, int c) { // 세로일때 날개 유효한지
55+
return isValid(r-1, c) && isValid(r+1, c) && board[r-1][c] == 0 && board[r+1][c] == 0;
56+
}
57+
58+
private static boolean canTurn(int r, int c, int t) {
59+
for (int i = r - 1; i <= r + 1; i++) {
60+
for (int j = c - 1; j <= c + 1; j++) {
61+
if (!isValid(i, j) || board[i][j]==1) return false;
62+
}
63+
}
64+
return true;
65+
}
66+
67+
private static boolean isValid(int x, int y) { // 좌표 유효성 검사
68+
return 0<=x && x<N && 0<=y && y<N;
69+
}
70+
71+
public static void main(String[] args) throws IOException {
72+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
73+
74+
N = Integer.parseInt(br.readLine());
75+
board = new int[N][N];
76+
visited = new int[N][N][2];
77+
78+
for (int i = 0; i < N; i++) {
79+
for (int j = 0; j < N; j++) {
80+
for (int k = 0; k < 2; k++) {
81+
visited[i][j][k] = -1;
82+
}
83+
}
84+
}
85+
86+
List<int[]> b = new ArrayList<>();
87+
List<int[]> e = new ArrayList<>();
88+
for (int i=0; i<N; i++){
89+
String line = br.readLine();
90+
for (int j = 0; j < N; j++) {
91+
char c = line.charAt(j);
92+
if (Character.isDigit(c)) {
93+
board[i][j] = c - '0';
94+
continue;
95+
}
96+
if (c=='B') b.add(new int[]{i, j});
97+
else if (c=='E') e.add(new int[]{i, j});
98+
board[i][j] = 0;
99+
}
100+
}
101+
102+
Collections.sort(b, (o1, o2) -> {
103+
if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]);
104+
return Integer.compare(o1[1], o2[1]);
105+
});
106+
107+
Collections.sort(e, (o1, o2) -> {
108+
if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]);
109+
return Integer.compare(o1[1], o2[1]);
110+
});
111+
112+
// 처음 중심 좌표 및 형태
113+
int tb = (b.get(0)[0] == b.get(1)[0]) ? 0 : 1; // 가로(0), 세로(1)
114+
int te = (e.get(0)[0] == e.get(1)[0]) ? 0 : 1;
115+
Node start = new Node(b.get(1)[0], b.get(1)[1], tb); // 중간값이 중심값
116+
target = new Node(e.get(1)[0], e.get(1)[1], te);
117+
118+
System.out.println(bfs(start));
119+
}
120+
121+
static class Node{
122+
int x, y, ty;
123+
124+
public Node(int x, int y, int ty) {
125+
this.x = x;
126+
this.y = y;
127+
this.ty = ty;
128+
}
129+
130+
@Override
131+
public String toString() {
132+
return "Node{" +
133+
"x=" + x +
134+
", y=" + y +
135+
", ty=" + ty +
136+
'}';
137+
}
138+
}
139+
140+
}

‎BOJ/10001-15000번/SB_13334.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package PriorityQueue;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.PriorityQueue;
7+
import java.util.StringTokenizer;
8+
9+
public class SB_13334 {
10+
static int N, d;
11+
static PriorityQueue<Node> pq = new PriorityQueue<>();
12+
public static void main(String[] args) throws IOException {
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
StringTokenizer st;
15+
N = Integer.parseInt(br.readLine());
16+
for (int i = 0; i < N; i++) {
17+
st = new StringTokenizer(br.readLine());
18+
int s = Integer.parseInt(st.nextToken());
19+
int e = Integer.parseInt(st.nextToken());
20+
pq.offer(new Node(Math.min(s, e), Math.max(s, e))); // 집과 사무실 중 작은게 시작, 큰게 끝
21+
}
22+
d = Integer.parseInt(br.readLine());
23+
24+
PriorityQueue<Integer> pre = new PriorityQueue<>(); // 이전 사람들의 정보를 저장하는 우선순위 큐
25+
int mx = 0;
26+
while (!pq.isEmpty()) {
27+
Node cur = pq.poll();
28+
int start = cur.e - d; // 철로의 시작 지점
29+
pre.offer(cur.s); // 현재 노드의 시작지점을 pre큐에 넣어주기
30+
while (!pre.isEmpty() && pre.peek() < start) { // 이전 사람들이 현재 철로에 속하지 못하면 빼주기
31+
pre.poll();
32+
}
33+
mx = Math.max(mx, pre.size());
34+
}
35+
36+
System.out.println(mx);
37+
}
38+
39+
static class Node implements Comparable<Node>{
40+
int s, e;
41+
42+
public Node(int s, int e) {
43+
this.s = s;
44+
this.e = e;
45+
}
46+
@Override
47+
public int compareTo(Node o) {
48+
if (this.e-o.e!=0) return this.e - o.e;
49+
return this.s-o.s;
50+
}
51+
}
52+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT ROUND(AVG(order_date = customer_pref_delivery_date)*100,2) as immediate_percentage
2+
FROM Delivery
3+
WHERE (customer_id, order_date) in (
4+
SELECT customer_id, min(order_date)
5+
FROM Delivery
6+
GROUP BY customer_id
7+
)

0 commit comments

Comments
(0)

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