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 763291c

Browse files
authored
Merge pull request #293 from GreatAlgorithm-Study/xubin
[21주차] 배수빈
2 parents 3c36e01 + 7abb68e commit 763291c

File tree

6 files changed

+367
-0
lines changed

6 files changed

+367
-0
lines changed

‎BOJ/1000-5000번/SB_1939.java‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.*;
5+
6+
public class SB_1939 {
7+
static int N,M, start, end;
8+
static List<List<Node>> adj = new ArrayList<>();
9+
static int[] dist;
10+
11+
private static int dijskra() {
12+
PriorityQueue<Node> pq = new PriorityQueue<>();
13+
pq.offer(new Node(start, Integer.MAX_VALUE)); // 최소값(최소값 중 최대)을 찾는것이기 때문에 맥스값으로 시작
14+
dist[start] = Integer.MAX_VALUE;
15+
16+
while (!pq.isEmpty()) {
17+
Node cur = pq.poll();
18+
if (cur.idx==end) return cur.c; // 도착점 도달 시 최대 중량 반환
19+
20+
if (cur.c < dist[cur.idx]) continue;
21+
for (Node nxt : adj.get(cur.idx)) {
22+
int weight = Math.min(cur.c, nxt.c); // 현재까지 중량과 다음 간선의 중량 중 최소값
23+
if (dist[nxt.idx] < weight) {
24+
dist[nxt.idx] = weight;
25+
pq.offer(new Node(nxt.idx, weight));
26+
}
27+
}
28+
}
29+
return 0; // 도달할 수 없는 경우
30+
}
31+
32+
public static void main(String[] args) throws IOException {
33+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
34+
StringTokenizer st = new StringTokenizer(br.readLine());
35+
36+
N = Integer.parseInt(st.nextToken());
37+
M = Integer.parseInt(st.nextToken());
38+
39+
dist = new int[N+1];
40+
Arrays.fill(dist, -1);
41+
for (int i = 0; i <= N; i++) {
42+
adj.add(new ArrayList<>());
43+
}
44+
45+
for (int i = 0; i < M; i++) {
46+
st = new StringTokenizer(br.readLine());
47+
int a = Integer.parseInt(st.nextToken());
48+
int b = Integer.parseInt(st.nextToken());
49+
int c = Integer.parseInt(st.nextToken());
50+
adj.get(a).add(new Node(b, c));
51+
adj.get(b).add(new Node(a, c));
52+
}
53+
st = new StringTokenizer(br.readLine());
54+
start = Integer.parseInt(st.nextToken());
55+
end = Integer.parseInt(st.nextToken());
56+
57+
System.out.println(dijskra());
58+
}
59+
60+
private static class Node implements Comparable<Node>{
61+
int idx, c;
62+
63+
public Node(int u, int c) {
64+
this.idx = u;
65+
this.c = c;
66+
}
67+
68+
@Override
69+
public int compareTo(Node o) {
70+
return o.c - this.c;
71+
}
72+
}
73+
}

‎BOJ/1000-5000번/SB_2169.java‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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_2169 {
7+
static int N, M;
8+
static int[][] board;
9+
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
14+
N = Integer.parseInt(st.nextToken());
15+
M = Integer.parseInt(st.nextToken());
16+
17+
board = new int[N][M];
18+
for (int i = 0; i < N; i++) {
19+
st = new StringTokenizer(br.readLine());
20+
for (int j = 0; j < M; j++) {
21+
board[i][j] = Integer.parseInt(st.nextToken());
22+
}
23+
}
24+
25+
int[][] dp = new int[N][M];
26+
27+
// 첫번째 행 초기화
28+
dp[0][0] = board[0][0];
29+
for (int j = 1; j < M; j++) { // 오른쪽으로만 탐색 가능(이미 지나온 길 탐색 불가)
30+
dp[0][j] = board[0][j] + dp[0][j - 1];
31+
}
32+
33+
for (int i = 1; i < N; i++) {
34+
int[] left = new int[M];
35+
int[] right = new int[M];
36+
37+
left[0] = dp[i - 1][0] + board[i][0]; // 0번째열은 일단 이전 행에서 아래로 내려와야함 (위에서 내려오는 한가지 경우)
38+
for (int j = 1; j < M; j++) { // 왼쪽에서 오는거, 위에서 내려오는 두가지 경우
39+
left[j] = Math.max(left[j - 1], dp[i - 1][j]) + board[i][j];
40+
}
41+
42+
right[M-1] = dp[i- 1][M-1] + board[i][M-1];
43+
for (int j = M - 2; j >= 0; j--) {
44+
right[j] = Math.max(right[j+1], dp[i-1][j]) + board[i][j];
45+
}
46+
47+
// 왼쪽 오른쪽 값 합침
48+
for (int j = 0; j < M; j++) {
49+
dp[i][j] = Math.max(left[j], right[j]);
50+
}
51+
}
52+
53+
System.out.println(dp[N-1][M-1]);
54+
}
55+
}

‎BOJ/1000-5000번/SB_2170.java‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.PriorityQueue;
5+
import java.util.StringTokenizer;
6+
7+
public class SB_2170 {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
StringTokenizer st;
11+
12+
PriorityQueue<Node> pq = new PriorityQueue<>();
13+
14+
int N = Integer.parseInt(br.readLine());
15+
for (int i = 0; i < N; i++) {
16+
st = new StringTokenizer(br.readLine());
17+
int s = Integer.parseInt(st.nextToken());
18+
int e = Integer.parseInt(st.nextToken());
19+
pq.offer(new Node(s, e));
20+
}
21+
22+
Node first = pq.poll();
23+
int start = first.s;
24+
int end = first.e;
25+
int cnt = 0;
26+
27+
while (!pq.isEmpty()) {
28+
Node cur = pq.poll();
29+
if (start <= cur.s && cur.s <= end) { // 현재 선분이랑 겹칠 경우
30+
end = Math.max(end, cur.e); // 더 큰 끝값으로 업데이트
31+
continue;
32+
}
33+
34+
// 겹치지 않음 (== 새로운 선분 시작)
35+
cnt += end - start; // 지금까지의 선분 길이 더해주기
36+
start = cur.s;
37+
end = cur.e;
38+
}
39+
cnt += end-start; // 마지막 선분 길이 업데이트
40+
41+
System.out.println(cnt);
42+
}
43+
static class Node implements Comparable<Node>{
44+
int s, e;
45+
46+
public Node(int s, int e) {
47+
this.s = s;
48+
this.e = e;
49+
}
50+
51+
@Override
52+
public int compareTo(Node o) {
53+
return this.s - o.s;
54+
}
55+
}
56+
}

‎BOJ/1000-5000번/SB_2504.java‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.ArrayDeque;
5+
import java.util.Deque;
6+
7+
public class SB_2504 {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
String line = br.readLine();
11+
12+
Deque<Character> stack = new ArrayDeque<>();
13+
int ans = 0;
14+
int tmp = 1;
15+
16+
for (int i = 0; i < line.length(); i++) {
17+
char cur = line.charAt(i);
18+
switch (cur) {
19+
case '(':
20+
stack.addFirst(cur);
21+
tmp*=2;
22+
break;
23+
case '[':
24+
stack.addFirst(cur);
25+
tmp*=3;
26+
break;
27+
case ')':
28+
if (stack.isEmpty() || stack.peekFirst() != '('){
29+
System.out.println(0);
30+
return;
31+
}
32+
if (line.charAt(i - 1) == '(') ans+=tmp;
33+
tmp/=2;
34+
stack.pollFirst();
35+
break;
36+
case ']':
37+
if (stack.isEmpty() || stack.peekFirst() != '['){
38+
System.out.println(0);
39+
return;
40+
}
41+
if (line.charAt(i-1)=='[') ans+=tmp;
42+
tmp/=3;
43+
stack.pollFirst();
44+
break;
45+
}
46+
}
47+
48+
// 남아있는 괄호 여부 체크
49+
if (stack.isEmpty()) System.out.println(ans);
50+
else System.out.println(0);
51+
}
52+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.*;
5+
6+
public class SB_두개의사탕 {
7+
static int N, M;
8+
static char[][] board;
9+
static int[] blue = new int[2];
10+
static int[] red = new int[2];
11+
static int[] dx = {-1, 1, 0, 0};
12+
static int[] dy = {0, 0, -1, 1};
13+
14+
private static Res tilt(int x, int y, int i) { // 방향에 따라 기울이기
15+
int move = 0;
16+
while (board[x + dx[i]][y + dy[i]] != '#' && board[x][y] != 'O') { // 다음에 위치할 값이 #이 아니고 현재 값이 도착점이 아니면 계속 움직임
17+
x += dx[i];
18+
y += dy[i]; // 좌표값 갱신 (i방향으로 이동)
19+
move++;
20+
}
21+
return new Res(x, y, move, board[x][y] == 'O');
22+
}
23+
24+
private static int bfs() {
25+
Deque<Node> que = new ArrayDeque<>();
26+
Set<String> visited = new HashSet<>();
27+
28+
que.offer(new Node(red[0], red[1], blue[0], blue[1], 0));
29+
visited.add("" + red[0] + red[1] + blue[0] + blue[1]);
30+
31+
while (!que.isEmpty()) {
32+
Node cur = que.poll();
33+
if (cur.cnt >= 10) return -1;
34+
35+
for (int i = 0; i < 4; i++) {
36+
// 구슬 각각 기울인 값
37+
Res nR = tilt(cur.rx, cur.ry, i);
38+
Res nB = tilt(cur.bx, cur.by, i);
39+
40+
if (nB.isGoal) continue;
41+
if (nR.isGoal) return cur.cnt + 1;
42+
if (nB.x == nR.x && nB.y == nR.y) { // 구슬이 같은 위치에 있다고 나왔을땐, 거리를 통해 실제 위치 파악
43+
if (nR.mv > nB.mv){ // 이동거리가 많은 것이 늦게 온것, 따라서 기존 위치보다 한 칸 뒤에 존재
44+
nR.x -= dx[i];
45+
nR.y -= dy[i];
46+
} else{
47+
nB.x -= dx[i];
48+
nB.y -= dy[i];
49+
}
50+
}
51+
52+
String state = "" + nR.x + nR.y + nB.x + nB.y;
53+
if (!visited.contains(state)) {
54+
visited.add(state);
55+
que.offer(new Node(nR.x, nR.y, nB.x, nB.y, cur.cnt + 1));
56+
}
57+
}
58+
}
59+
return -1;
60+
}
61+
public static void main(String[] args) throws IOException {
62+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
63+
StringTokenizer st = new StringTokenizer(br.readLine());
64+
65+
N = Integer.parseInt(st.nextToken());
66+
M = Integer.parseInt(st.nextToken());
67+
68+
board = new char[N][M];
69+
70+
for (int i = 0; i < N; i++) {
71+
String line = br.readLine();
72+
for (int j = 0; j < M; j++) {
73+
board[i][j] = line.charAt(j);
74+
if (board[i][j]=='B') {
75+
blue[0] = i;
76+
blue[1] = j;
77+
}
78+
else if (board[i][j]=='R') {
79+
red[0] = i;
80+
red[1] = j;
81+
}
82+
}
83+
}
84+
85+
System.out.println(bfs());
86+
}
87+
88+
private static class Node{
89+
int rx, ry, bx, by, cnt;
90+
91+
public Node(int rx, int ry, int bx, int by, int cnt) {
92+
this.rx = rx;
93+
this.ry = ry;
94+
this.bx = bx;
95+
this.by = by;
96+
this.cnt = cnt;
97+
}
98+
}
99+
100+
private static class Res{
101+
int x, y, mv;
102+
boolean isGoal;
103+
104+
public Res(int x, int y, int mv, boolean isGoal) {
105+
this.x = x;
106+
this.y = y;
107+
this.mv = mv;
108+
this.isGoal = isGoal;
109+
}
110+
}
111+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
WITH ColonyData AS (
2+
SELECT
3+
YEAR(DIFFERENTIATION_DATE) AS YEAR,
4+
SIZE_OF_COLONY,
5+
ID
6+
FROM ECOLI_DATA
7+
),
8+
MaxColony AS (
9+
SELECT YEAR(DIFFERENTIATION_DATE) AS YEAR,
10+
MAX(SIZE_OF_COLONY) AS MX
11+
FROM ECOLI_DATA
12+
GROUP BY YEAR(DIFFERENTIATION_DATE)
13+
)
14+
15+
SELECT c.YEAR,
16+
(m.MX - c.SIZE_OF_COLONY) AS YEAR_DEV,
17+
c.ID
18+
FROM ColonyData c
19+
JOIN MaxColony m ON C.YEAR = M.YEAR
20+
ORDER BY c.YEAR, YEAR_DEV;

0 commit comments

Comments
(0)

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