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

[14주차] 배수빈 #193

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
baexxbin merged 8 commits into main from xubin
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions BOJ/20001-25000번/SB_20181.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class SB_20181 {
static int N, K;
static int[] arr;
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());
K = Integer.parseInt(st.nextToken());

arr = new int[N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}

long[] dp = new long[N + 1];

long happy = 0;
int left = 0;
for (int right = 0; right < N; right++) {
happy += arr[right];

while (happy >= K) {
dp[right + 1] = Math.max(dp[right + 1], dp[left] + happy - K); // dp[left]는 이전 구간의 최대값(이전 최종 right의 위치)
happy -= arr[left++];
}

dp[right + 1] = Math.max(dp[right], dp[right + 1]); // 현재까지의 최대값과 갱신된 최대값 비교
}

System.out.println(Arrays.toString(dp));
}
}
28 changes: 28 additions & 0 deletions BOJ/20001-25000번/SB_20291.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class SB_20291 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());

TreeMap<String, Integer> map = new TreeMap<>();
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine(), ".");
String name = st.nextToken();
String ext = st.nextToken();
map.put(ext, map.getOrDefault(ext, 0) + 1);
}

for (Map.Entry<String, Integer> entry : map.entrySet()) {
sb.append(entry.getKey()).append(" ").append(entry.getValue()).append('\n');
}
System.out.println(sb);
}
}
90 changes: 90 additions & 0 deletions BOJ/20001-25000번/SB_22944.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package bfs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class SB_22944 {
static int N, H, D;
static int K = 0;
static char[][] board;
static Node start;
static int[] dx = {-1, 1, 0, 0};
static int[] dy = {0, 0, -1, 1};

private static int bfs() {
Queue<Node> que = new ArrayDeque<>();
int[][][] visited = new int[N][N][K + 1];
for (int[][] box : visited){
for (int[] row : box){
Arrays.fill(row, -1);
}
}
que.offer(new Node(start.x, start.y, start.h, start.u, start.cntU));
visited[start.x][start.y][0] = 0;

while (!que.isEmpty()) {
Node cur = que.poll();
if (cur.h==0) continue; // 체력 0이면 죽음
if (board[cur.x][cur.y]=='E') { // 도착하면 탈출
return visited[cur.x][cur.y][cur.cntU];
}

for (int i = 0; i < 4; i++) {
int nx = cur.x + dx[i];
int ny = cur.y + dy[i];
if (!isValid(nx, ny) || visited[nx][ny][cur.cntU]!=-1) continue;
if (board[nx][ny] == 'U') {
if (cur.cntU + 1 <= K && visited[nx][ny][cur.cntU + 1] == -1) { // 우산 안넘치게 조건걸기
que.add(new Node(nx, ny, cur.h, D, cur.cntU + 1));
visited[nx][ny][cur.cntU+1] = visited[cur.x][cur.y][cur.cntU] + 1;
}
}
else {
if (cur.u > 0) que.add(new Node(nx, ny, cur.h, cur.u - 1, cur.cntU));
else que.add(new Node(nx, ny, cur.h-1, cur.u, cur.cntU));
visited[nx][ny][cur.cntU] = visited[cur.x][cur.y][cur.cntU] + 1;
}
}
}
return -1;
}

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));
StringTokenizer st = new StringTokenizer(br.readLine());

N = Integer.parseInt(st.nextToken());
H = Integer.parseInt(st.nextToken());
D = Integer.parseInt(st.nextToken());

board = new char[N][N];
for (int i = 0; i < N; i++) {
String line = br.readLine();
for (int j = 0; j < N; j++) {
board[i][j] = line.charAt(j);
if (board[i][j]=='S') start = new Node(i, j, H, 0, 0);
if (board[i][j]=='U') K++;
}
}

System.out.println(bfs());
}

static class Node{
int x, y, h, u;
int cntU; // 우산 주운 개수

public Node(int x, int y, int h, int u, int cntU) {
this.x = x;
this.y = y;
this.h = h;
this.u = u;
this.cntU = cntU;
}
}
}
Loading

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