-
Notifications
You must be signed in to change notification settings - Fork 4
[14주차] 고다혜 #192
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
[14주차] 고다혜 #192
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d6134e6
고다혜: [CT] 색깔 폭탄_241209
KodaHye ad1ccb5
고다혜: [BOJ] 22944 죽음의 비_241210
KodaHye cfe5ffc
고다혜: [SQL] Movie Rating_241210
KodaHye 48d1f81
고다혜: [BOJ] 20291 파일 정리_241211
KodaHye 92f8cdb
고다혜: [PG] 340211 충돌위험 찾기_241212
KodaHye e456234
고다혜: [PG] 118669 등산코스 정하기_241213
KodaHye 8af9a2f
고다혜: [SQL] Restaurant Growth_241212
KodaHye 6819f9c
고다혜: [BOJ] 20181 꿈툴꿈틀 호석 애벌레 - 효율성_241211
KodaHye 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
40 changes: 40 additions & 0 deletions
BOJ/20001-25000번/DH_20181.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,40 @@ | ||
import java.io.*; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class DH_20181 { | ||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int N = Integer.parseInt(st.nextToken()); | ||
int K = Integer.parseInt(st.nextToken()); | ||
|
||
int[] arr = new int[N + 1]; | ||
long[] dp = new long[N + 1]; | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
|
||
for(int i = 0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken()); | ||
|
||
long sum = 0, tmp = 0, result = 0; | ||
int s = 0, e = 0; | ||
|
||
// dp[i]: i 지점까지 최선을 다했을 때, 얻을 수 있는 점수 | ||
while(e < N + 1) { | ||
if(sum >= K) { | ||
tmp = s == 0 ? 0: Math.max(tmp, dp[s - 1]); | ||
// tmp + sum - K | ||
// : (s전까지 최선을 다했을 때, 얻을 수 있는 점수) + (s ~ e까지 합계) - K | ||
// else 부분에서 e++가 되었으므로 dp[e - 1]을 해줘서 sum을 한 범위까지 확인할 수 있도록 함 | ||
dp[e - 1] = Math.max(dp[e - 1], tmp + sum - K); | ||
result = Math.max(result, dp[e - 1]); | ||
sum -= arr[s++]; | ||
|
||
} else { | ||
sum += arr[e++]; | ||
} | ||
} | ||
System.out.println(result); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
BOJ/20001-25000번/DH_20291.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,29 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 파일 정리 | ||
*/ | ||
|
||
public class DH_20291 { | ||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
int N = Integer.parseInt(br.readLine()); | ||
|
||
TreeMap<String, Integer> treeMap = new TreeMap<>(); | ||
|
||
for(int i = 0; i < N; i++) { | ||
String s = br.readLine().split("\\.")[1]; | ||
if(treeMap.containsKey(s)) treeMap.put(s, treeMap.get(s) + 1); | ||
else treeMap.put(s, 1); | ||
} | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
for(String key: treeMap.keySet()) { | ||
sb.append(key).append(" ").append(treeMap.get(key)).append("\n"); | ||
} | ||
|
||
System.out.println(sb); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
BOJ/20001-25000번/DH_22944.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,111 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/* | ||
* 죽음의 비 | ||
*/ | ||
|
||
public class DH_22944 { | ||
static int[] dr = {-1, 1, 0, 0}, dc = {0, 0, -1, 1}; | ||
static class Point { | ||
int k, r, c, d, p, u; | ||
public Point(int k, int r, int c, int d, int p, int u) { | ||
this.k = k; | ||
this.r = r; | ||
this.c = c; | ||
this.d = d; | ||
this.p = p; | ||
this.u = u; | ||
} | ||
} | ||
|
||
static int N, H, D; | ||
static char[][] map; | ||
static boolean[][][] v; | ||
static Deque<Point> q; | ||
|
||
public static void main(String[] args) throws Exception { | ||
initInput(); | ||
System.out.println(solution()); | ||
} | ||
|
||
static int solution() { | ||
int result = -1; | ||
|
||
while(!q.isEmpty()) { | ||
Point current = q.poll(); | ||
|
||
if(map[current.r][current.c] == 'E') { | ||
result = current.d; | ||
break; | ||
} | ||
|
||
for(int d = 0; d < 4; d++) { | ||
int nr = current.r + dr[d]; | ||
int nc = current.c + dc[d]; | ||
int nk = current.k; | ||
int np = current.p; | ||
int nu = current.u; | ||
|
||
if(!check(nr, nc) || v[current.k][nr][nc]) continue; | ||
|
||
if(map[nr][nc] == '.') { | ||
if(nu > 0) nu -= 1; | ||
else np -= 1; | ||
} | ||
|
||
// 우산이라면 | ||
else if(map[nr][nc] == 'U') { | ||
map[nr][nc] = '.'; | ||
nu = D - 1; | ||
nk = current.k + 1; | ||
} | ||
|
||
if(np == 0) continue; | ||
|
||
v[current.k][nr][nc] = true; | ||
q.add(new Point(nk, nr, nc, current.d + 1, np, nu)); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
static boolean check(int r, int c) { | ||
return r >= 0 && r < N && c >= 0 && c < N; | ||
} | ||
|
||
static void initInput() throws Exception { | ||
System.setIn(new FileInputStream("./input/BOJ22944.txt")); | ||
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()); // 우산의 내구도 | ||
|
||
q = new ArrayDeque<Point>(); | ||
int uCnt = 0; | ||
|
||
int sr = 0, sc =0; | ||
|
||
map = new char[N][N]; | ||
|
||
for(int r = 0; r < N; r++) { | ||
String s = br.readLine(); | ||
map[r] = s.toCharArray(); | ||
|
||
for(int c = 0; c < N; c++) { | ||
if(map[r][c] == 'S') { | ||
sr = r; sc = c; | ||
map[r][c] = '.'; | ||
} | ||
if(map[r][c] == 'U') uCnt += 1; | ||
} | ||
} | ||
|
||
v = new boolean[uCnt + 1][N][N]; | ||
q.add(new Point(0, sr, sc, 0, H, 0)); | ||
v[0][sr][sc] = true; | ||
} | ||
} |
197 changes: 197 additions & 0 deletions
CodeTree/2021-2022년/DH_색깔폭탄.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,197 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class DH_색깔폭탄 { | ||
static class Point { | ||
int r, c; | ||
public Point(int r, int c) { | ||
this.r = r; | ||
this.c = c; | ||
} | ||
} | ||
static int N, M, score; | ||
static int[][] map; | ||
static final int INF = Integer.MAX_VALUE; | ||
static final int RED = -2, BLACK = -1, EMPTY = 0; | ||
static int[] dr = {-1, 1, 0, 0}, dc = {0, 0, -1, 1}; | ||
|
||
public static void main(String[] args) throws Exception { | ||
initInput(); | ||
solution(); | ||
System.out.println(score); | ||
} | ||
|
||
static void solution() { | ||
Deque<Point> bomb; | ||
while((bomb = step1()).size() >= 2) { // 폭탄 묶음 찾기 | ||
step2(bomb); // 폭탄 터지기 | ||
step3(); // 중력 작용하기 | ||
step4(); // 반시계 방향으로 90도 회전하기 | ||
step3(); // 중력 작용하기 | ||
} | ||
} | ||
|
||
// 폭탄 묶음 찾기 | ||
static Deque<Point> step1() { | ||
Deque<Point> result = new ArrayDeque<Point>(); // 우선순위에 따라 폭탄이 터질 위치를 저장하는 큐 | ||
Deque<Point> tmp = new ArrayDeque<Point>(); // bfs탐색했던 위치들을 모두 저장하는 큐 | ||
Deque<Point> q = new ArrayDeque<Point>(); // bfs 탐색하는 큐 | ||
|
||
// 폭탄묶음의 크기, 빨간색 폭탄의 개수, | ||
int groupSize = -INF, redCnt = INF; | ||
|
||
// 빨간색 폭탄은 bfs를 할 때마다 또 다시 사용할 수 있으므로 | ||
// 따로 빨간색을 제외한 색깔 폭탄을 확인했는지 구분해주기 위해 bfs에서 사용하는 방문 배열 외에 또 다른 2차원 boolean 배열을 만들어줌 | ||
boolean[][] checkColor = new boolean[N][N]; | ||
|
||
// bfs 탐색을 하는데, 우선순위에 따른 폭탄 묶음을 구하기 위해 | ||
// r은 N - 1부터 시작하고, c는 0부터 시작함 | ||
// 그리고 빨간 색이 아닌 다른 색깔 폭탄일 때 bfs 탐색 시작 | ||
for(int r = N - 1; r >= 0; r--) { | ||
for(int c = 0; c < N; c++) { | ||
if(!isColor(map[r][c]) || checkColor[r][c]) continue; | ||
|
||
boolean[][] v = new boolean[N][N]; | ||
int currentRedCnt = 0; // 현재 위치에서 폭탄 묶음을 구성할 때, 빨간 폭탄의 개수 | ||
int currentSize = 1; // 현재 위치에서 폭탄 묶음을 구성할 때, 폭탄 묶음의 크기 | ||
|
||
tmp.clear(); | ||
|
||
q.add(new Point(r, c)); | ||
tmp.add(new Point(r, c)); | ||
|
||
v[r][c] = true; | ||
|
||
while(!q.isEmpty()) { | ||
Point current = q.poll(); | ||
|
||
for(int d = 0; d < 4; d++) { | ||
int nr = current.r + dr[d]; | ||
int nc = current.c + dc[d]; | ||
|
||
// 범위에 벗어났거나, 확인을 한 곳이거나, 돌이 있거나, 빈 공간이라면 continue | ||
if(!check(nr, nc) || v[nr][nc] || map[nr][nc] == BLACK || map[nr][nc] == EMPTY) continue; | ||
|
||
// 빨간 폭탄도 아니고, 검정폭탄도 아닌데, 현재 자신의 색깔과 다른 경우 | ||
if((map[nr][nc] > 0 && map[nr][nc] != map[r][c])) continue; | ||
|
||
// 빨간 폭탄일 경우 | ||
if(map[nr][nc] == RED) currentRedCnt += 1; | ||
|
||
q.add(new Point(nr, nc)); | ||
tmp.add(new Point(nr, nc)); | ||
|
||
v[nr][nc] = true; | ||
currentSize += 1; | ||
} | ||
} | ||
|
||
// 폭탄 묶음 크기가 큰 폭탄부터 | ||
if(groupSize < currentSize) { | ||
result.clear(); | ||
result.addAll(tmp); | ||
|
||
groupSize = currentSize; | ||
redCnt = currentRedCnt; | ||
} | ||
// 폭탄 묶음 크기가 같다면, 빨간 폭탄의 개수 확인하기 | ||
else if(groupSize == currentSize) { | ||
if(currentRedCnt < redCnt) { | ||
result.clear(); | ||
result.addAll(tmp); | ||
|
||
groupSize = currentSize; | ||
redCnt = currentRedCnt; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// 폭탄 터지기 | ||
static void step2(Deque<Point> bomb) { | ||
score += bomb.size() * bomb.size(); | ||
|
||
while(!bomb.isEmpty()) { | ||
Point current = bomb.poll(); | ||
map[current.r][current.c] = EMPTY; // 빈 공간으로 바꿔주기 | ||
} | ||
} | ||
|
||
// 중력 작용 | ||
// 폭탄들이 있으면 큐에 넣어주고, 돌이 나온다면 gravity(기준선)을 기준으로 쌓아주기 | ||
static void step3() { | ||
int[][] tmp = new int[N][N]; | ||
Deque<Integer> q = new ArrayDeque<Integer>(); | ||
|
||
for(int c = 0; c < N; c++) { | ||
int gravity = N; | ||
|
||
for(int r = N - 1; r >= 0; r--) { | ||
if(isBomb(map[r][c])) q.add(map[r][c]); | ||
if(map[r][c] == BLACK) { | ||
tmp[r][c] = BLACK; | ||
while(!q.isEmpty()) tmp[--gravity][c] = q.poll(); | ||
gravity = r; | ||
} | ||
} | ||
|
||
while(!q.isEmpty()) tmp[--gravity][c] = q.poll(); | ||
} | ||
|
||
map = tmp; | ||
} | ||
|
||
// 반시계 방향으로 회전 | ||
// (r, c) -> (N - 1 - c, r) 로 바뀜 | ||
static void step4() { | ||
int[][] tmp = new int[N][N]; | ||
for(int r = 0; r < N; r++) { | ||
for(int c = 0; c < N; c++) { | ||
tmp[N - 1 - c][r] = map[r][c]; | ||
} | ||
} | ||
|
||
map = tmp; | ||
} | ||
|
||
static boolean check(int r, int c) { | ||
return r >= 0 && r < N && c >= 0 && c < N; | ||
} | ||
|
||
// 빨간색을 제외한 모든 색깔 폭탄 | ||
static boolean isColor(int n) { | ||
return n > 0 && n < M + 1; | ||
} | ||
|
||
static boolean isBomb(int n) { | ||
return isColor(n) || n == RED; | ||
} | ||
|
||
static void printMapInfo() { | ||
System.out.println("printMapInfo ---------------------"); | ||
for(int r = 0; r < map.length; r++) { | ||
System.out.println(Arrays.toString(map[r])); | ||
} | ||
} | ||
|
||
static void initInput() throws Exception { | ||
System.setIn(new FileInputStream("./input/색깔폭탄.txt")); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
M = Integer.parseInt(st.nextToken()); | ||
|
||
map = new int[N][N]; | ||
for(int r = 0; r < N; r++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for(int c = 0; c < N; c++) { | ||
map[r][c] = Integer.parseInt(st.nextToken()); | ||
if(map[r][c] == 0) map[r][c] = RED; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.