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 6b5b140

Browse files
Merge pull request #193 from GreatAlgorithm-Study/xubin
[14주차] 배수빈
2 parents 7f10df7 + 0134758 commit 6b5b140

File tree

8 files changed

+626
-0
lines changed

8 files changed

+626
-0
lines changed

‎BOJ/20001-25000번/SB_20181.java‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.Arrays;
5+
import java.util.StringTokenizer;
6+
7+
public class SB_20181 {
8+
static int N, K;
9+
static int[] arr;
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+
K = Integer.parseInt(st.nextToken());
16+
17+
arr = new int[N];
18+
st = new StringTokenizer(br.readLine());
19+
for (int i = 0; i < N; i++) {
20+
arr[i] = Integer.parseInt(st.nextToken());
21+
}
22+
23+
long[] dp = new long[N + 1];
24+
25+
long happy = 0;
26+
int left = 0;
27+
for (int right = 0; right < N; right++) {
28+
happy += arr[right];
29+
30+
while (happy >= K) {
31+
dp[right + 1] = Math.max(dp[right + 1], dp[left] + happy - K); // dp[left]는 이전 구간의 최대값(이전 최종 right의 위치)
32+
happy -= arr[left++];
33+
}
34+
35+
dp[right + 1] = Math.max(dp[right], dp[right + 1]); // 현재까지의 최대값과 갱신된 최대값 비교
36+
}
37+
38+
System.out.println(Arrays.toString(dp));
39+
}
40+
}

‎BOJ/20001-25000번/SB_20291.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.Map;
5+
import java.util.StringTokenizer;
6+
import java.util.TreeMap;
7+
8+
public class SB_20291 {
9+
public static void main(String[] args) throws IOException {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
StringTokenizer st;
12+
StringBuilder sb = new StringBuilder();
13+
int N = Integer.parseInt(br.readLine());
14+
15+
TreeMap<String, Integer> map = new TreeMap<>();
16+
for (int i = 0; i < N; i++) {
17+
st = new StringTokenizer(br.readLine(), ".");
18+
String name = st.nextToken();
19+
String ext = st.nextToken();
20+
map.put(ext, map.getOrDefault(ext, 0) + 1);
21+
}
22+
23+
for (Map.Entry<String, Integer> entry : map.entrySet()) {
24+
sb.append(entry.getKey()).append(" ").append(entry.getValue()).append('\n');
25+
}
26+
System.out.println(sb);
27+
}
28+
}

‎BOJ/20001-25000번/SB_22944.java‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package bfs;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.*;
7+
8+
public class SB_22944 {
9+
static int N, H, D;
10+
static int K = 0;
11+
static char[][] board;
12+
static Node start;
13+
static int[] dx = {-1, 1, 0, 0};
14+
static int[] dy = {0, 0, -1, 1};
15+
16+
private static int bfs() {
17+
Queue<Node> que = new ArrayDeque<>();
18+
int[][][] visited = new int[N][N][K + 1];
19+
for (int[][] box : visited){
20+
for (int[] row : box){
21+
Arrays.fill(row, -1);
22+
}
23+
}
24+
que.offer(new Node(start.x, start.y, start.h, start.u, start.cntU));
25+
visited[start.x][start.y][0] = 0;
26+
27+
while (!que.isEmpty()) {
28+
Node cur = que.poll();
29+
if (cur.h==0) continue; // 체력 0이면 죽음
30+
if (board[cur.x][cur.y]=='E') { // 도착하면 탈출
31+
return visited[cur.x][cur.y][cur.cntU];
32+
}
33+
34+
for (int i = 0; i < 4; i++) {
35+
int nx = cur.x + dx[i];
36+
int ny = cur.y + dy[i];
37+
if (!isValid(nx, ny) || visited[nx][ny][cur.cntU]!=-1) continue;
38+
if (board[nx][ny] == 'U') {
39+
if (cur.cntU + 1 <= K && visited[nx][ny][cur.cntU + 1] == -1) { // 우산 안넘치게 조건걸기
40+
que.add(new Node(nx, ny, cur.h, D, cur.cntU + 1));
41+
visited[nx][ny][cur.cntU+1] = visited[cur.x][cur.y][cur.cntU] + 1;
42+
}
43+
}
44+
else {
45+
if (cur.u > 0) que.add(new Node(nx, ny, cur.h, cur.u - 1, cur.cntU));
46+
else que.add(new Node(nx, ny, cur.h-1, cur.u, cur.cntU));
47+
visited[nx][ny][cur.cntU] = visited[cur.x][cur.y][cur.cntU] + 1;
48+
}
49+
}
50+
}
51+
return -1;
52+
}
53+
54+
private static boolean isValid(int x, int y) {
55+
return 0 <= x && x < N && 0 <= y && y < N;
56+
}
57+
public static void main(String[] args) throws IOException {
58+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
59+
StringTokenizer st = new StringTokenizer(br.readLine());
60+
61+
N = Integer.parseInt(st.nextToken());
62+
H = Integer.parseInt(st.nextToken());
63+
D = Integer.parseInt(st.nextToken());
64+
65+
board = new char[N][N];
66+
for (int i = 0; i < N; i++) {
67+
String line = br.readLine();
68+
for (int j = 0; j < N; j++) {
69+
board[i][j] = line.charAt(j);
70+
if (board[i][j]=='S') start = new Node(i, j, H, 0, 0);
71+
if (board[i][j]=='U') K++;
72+
}
73+
}
74+
75+
System.out.println(bfs());
76+
}
77+
78+
static class Node{
79+
int x, y, h, u;
80+
int cntU; // 우산 주운 개수
81+
82+
public Node(int x, int y, int h, int u, int cntU) {
83+
this.x = x;
84+
this.y = y;
85+
this.h = h;
86+
this.u = u;
87+
this.cntU = cntU;
88+
}
89+
}
90+
}

0 commit comments

Comments
(0)

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