-
Notifications
You must be signed in to change notification settings - Fork 4
[14주차] 이혜원 #194
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
Merged
[14주차] 이혜원 #194
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a7cf66f
이혜원: [BOJ] 22944 죽음의 비_241210
icegosimperson d4180e4
이혜원: [SQL] Students and Examinations_241210
icegosimperson 703be67
이혜원: [BOJ] 20181 꿈틀꿈틀 호석 애벌레 - 효율성_241211
icegosimperson ee6b0b0
이혜원: [BOJ] 20291 파일 정리_241211
icegosimperson c55a1be
이혜원: [SQL] Odd and Even Transactions_241212
icegosimperson 2704a2c
이혜원: [PG] 340211 충돌위험 찾기_241212
icegosimperson 06a8d25
이혜원: [CT] 색깔 폭탄_241209
icegosimperson e09447b
이혜원: [PG] 등산코스 정하기_241213
icegosimperson 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
36 changes: 36 additions & 0 deletions
BOJ/20001-25000번/HW_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,36 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class HW_20181 { | ||
public static void main(String[] args) throws IOException { | ||
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]; | ||
long[] dp = new long[N+1]; // dp[i] : i번쨰 먹이까지의 최대 탈피 에너지 | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for(int i=0; i<N; i++){ | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
long sum = 0; // 만족도 합 | ||
int left = 0; | ||
|
||
for(int right=1; right <=N; right++){ | ||
sum += arr[right-1]; | ||
|
||
while(K <= sum){ | ||
dp[right] = Math.max(dp[right], dp[left] + sum - K); // 탈피 에너지 계산 | ||
sum -= arr[left]; | ||
left++; // 구간 축소 | ||
} | ||
dp[right] = Math.max(dp[right], dp[right - 1]); // 최대 탈피 에너지값 출력 | ||
} | ||
System.out.println(dp[N]); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
BOJ/20001-25000번/HW_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,23 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class HW_20291 { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int N = Integer.parseInt(br.readLine()); | ||
|
||
TreeMap<String, Integer> words = new TreeMap<>(); | ||
|
||
for(int i=0; i<N; i++) { | ||
String input = br.readLine(); | ||
String extension = input.substring(input.lastIndexOf('.')+1); | ||
|
||
words.put(extension, words.getOrDefault(extension, 0)+1); | ||
} | ||
|
||
for(Map.Entry<String, Integer> entry : words.entrySet()) { | ||
System.out.println(entry.getKey() + " " + entry.getValue()); | ||
} | ||
|
||
} | ||
} |
99 changes: 99 additions & 0 deletions
BOJ/20001-25000번/HW_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,99 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class HW_22944 { | ||
static int N, H, D; | ||
static char[][] board; | ||
static int[][] check; | ||
static int[] dx = {-1, 1, 0, 0}; | ||
static int[] dy = {0, 0, -1, 1}; | ||
|
||
static class Node { | ||
int x, y, h, d, m; | ||
|
||
public Node(int x, int y, int h, int d, int m) { | ||
this.x = x; | ||
this.y = y; | ||
this.h = h; // 현재 체력 | ||
this.d = d; // 우산 내구도 | ||
this.m = m; // 이동 횟수 | ||
} | ||
} | ||
|
||
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]; | ||
check = new int[N][N]; | ||
|
||
int startX = 0, startY = 0; | ||
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') { | ||
startX = i; | ||
startY = j; | ||
} | ||
} | ||
} | ||
|
||
for (int i = 0; i < N; i++) { | ||
Arrays.fill(check[i], -1); | ||
} | ||
|
||
int result = bfs(startX, startY); | ||
System.out.println(result); | ||
} | ||
|
||
public static int bfs(int sx, int sy) { | ||
Queue<Node> queue = new LinkedList<>(); | ||
queue.add(new Node(sx, sy, H, 0, 0)); // 시작점 추가 | ||
check[sx][sy] = H; // 시작점 방문 처리 | ||
|
||
while (!queue.isEmpty()) { | ||
Node cur = queue.poll(); | ||
|
||
for (int i = 0; i < 4; i++) { | ||
int newH = cur.h, newD = cur.d, newM = cur.m; | ||
int nx = cur.x + dx[i]; | ||
int ny = cur.y + dy[i]; | ||
|
||
|
||
if (!isValid(nx, ny)) | ||
continue; | ||
|
||
if (board[nx][ny] == 'E') { // 안전지대에 도달하면 이동 횟수 반환 | ||
return newM + 1; | ||
} | ||
|
||
if (board[nx][ny] == 'U') | ||
newD = D; | ||
|
||
if (newD > 0) { | ||
newD--; | ||
} else { | ||
newH--; | ||
} | ||
|
||
if (newH == 0) | ||
continue; | ||
|
||
if (check[nx][ny] < newH + newD) { | ||
check[nx][ny] = newH + newD; | ||
queue.add(new Node(nx, ny, newH, newD, newM + 1)); | ||
} | ||
} | ||
} | ||
return -1; // 안전지대에 도달하지 못한 경우 | ||
} | ||
|
||
public static boolean isValid(int nx, int ny) { | ||
return 0<= nx && nx < N && 0 <=ny && ny < N; | ||
} | ||
} |
179 changes: 179 additions & 0 deletions
CodeTree/2021-2022년/HW_색깔_폭탄.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,179 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class HW_색깔_폭탄 { | ||
static int n, m; | ||
static int[][] board; | ||
static int score = 0; | ||
static int[] dx = {-1,1,0,0}; | ||
static int[] dy = {0,0,-1,1}; | ||
|
||
static class Bomb { | ||
int size; | ||
int redCount; | ||
int stdX; | ||
int stdY; | ||
List<int[]> blocks; // 폭탄 묶음 내 좌표 | ||
|
||
Bomb(int size, int redCount, int stdX, int stdY, List<int[]> blocks) { | ||
this.size = size; | ||
this.redCount = redCount; | ||
this.stdX = stdX; | ||
this.stdY = stdY; | ||
this.blocks = blocks; | ||
} | ||
} | ||
|
||
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()); | ||
m = Integer.parseInt(st.nextToken()); | ||
board = new int[n][n]; | ||
|
||
for (int i=0; i<n; i++){ | ||
st = new StringTokenizer(br.readLine()); | ||
for (int j=0; j<n; j++){ | ||
board[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
while (true) { | ||
Bomb group = find(); | ||
if (group == null || group.size < 2) { | ||
break; | ||
} | ||
score += group.size * group.size; | ||
remove(group); | ||
gravity(); | ||
board = rotate(board); | ||
gravity(); | ||
} | ||
|
||
System.out.println(score); | ||
} | ||
|
||
static Bomb find() { | ||
List<Bomb> candidates = new ArrayList<>(); | ||
|
||
for (int i=0; i<n; i++){ | ||
for (int j=0; j<n; j++){ | ||
int color = board[i][j]; | ||
if (0 < color && color <= m) { | ||
Bomb bg = bfs(i, j, color); | ||
if (bg != null && 2 <=bg.size) { | ||
candidates.add(bg); | ||
} | ||
} | ||
} | ||
} | ||
if (candidates.isEmpty()){ | ||
return null; | ||
} | ||
// 우선순위 정렬 | ||
candidates.sort((a,b)-> { | ||
if (a.size != b.size) // 1. size 내림차순 | ||
return b.size - a.size; | ||
if (a.redCount != b.redCount) // 2. redCount 오름차순 | ||
return a.redCount - b.redCount; | ||
if (a.stdX != b.stdX) // 3. 기준 행 내림차순 | ||
return b.stdX - a.stdX; | ||
return a.stdY - b.stdY; // 4. 기준 열 오름차순 | ||
}); | ||
|
||
return candidates.get(0); | ||
} | ||
|
||
static Bomb bfs(int sx, int sy, int color) { | ||
boolean[][] visited = new boolean[n][n]; | ||
Queue<int[]> q = new LinkedList<>(); | ||
q.offer(new int[]{sx, sy}); | ||
visited[sx][sy] = true; | ||
|
||
List<int[]> group = new ArrayList<>(); | ||
group.add(new int[]{sx, sy}); | ||
int redCount = (board[sx][sy] == 0) ? 1 : 0; | ||
|
||
while(!q.isEmpty()){ | ||
int[] cur = q.poll(); | ||
int x=cur[0], y=cur[1]; | ||
|
||
for (int k=0; k<4; k++){ | ||
int nx = x + dx[k]; | ||
int ny = y + dy[k]; | ||
if (!isValid(nx, ny)) { | ||
continue; | ||
} | ||
if (board[nx][ny] == -1) { // 검은 돌 제외 | ||
continue; | ||
} | ||
if (!visited[nx][ny]) { | ||
if (board[nx][ny] == color || board[nx][ny] == 0) { | ||
visited[nx][ny] = true; | ||
q.offer(new int[]{nx,ny}); | ||
group.add(new int[]{nx,ny}); | ||
if (board[nx][ny] == 0) { | ||
redCount++; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (group.size()<2) return null; | ||
|
||
|
||
int targetX=-1; | ||
int targetY=-1; | ||
for (int i=0; i<group.size(); i++) { | ||
int gx = group.get(i)[0]; | ||
int gy = group.get(i)[1]; | ||
if (board[gx][gy]!=0) { // 기준점 찾기: 빨간 아닌 폭탄 중 x 최대, x 같다면 y 최소 | ||
if (gx > targetX || (gx==targetX && (targetY==-1 || gy < targetY))) { | ||
targetX = gx; | ||
targetY = gy; | ||
} | ||
} | ||
} | ||
return new Bomb(group.size(), redCount, targetX, targetY, group); | ||
} | ||
|
||
static void remove(Bomb b) { | ||
for (int i=0; i<b.blocks.size(); i++) { | ||
int x=b.blocks.get(i)[0]; | ||
int y=b.blocks.get(i)[1]; | ||
board[x][y] = -2; // 빈칸 처리 | ||
} | ||
} | ||
|
||
static void gravity() { | ||
for (int y=0; y<n; y++){ | ||
for (int x=n-1; x>=0; x--){ | ||
if (board[x][y] > -1) { | ||
int nx = x; | ||
while(true) { | ||
int down = nx+1; | ||
if (down>=n) break; | ||
if (board[down][y]!=-2) break; | ||
board[down][y]=board[nx][y]; | ||
board[nx][y]=-2; | ||
nx=down; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
static int[][] rotate(int[][] arr) { | ||
int[][] newBoard = new int[n][n]; | ||
for (int x=0; x<n; x++){ | ||
for (int y=0; y<n; y++){ | ||
newBoard[n-1-y][x]=arr[x][y]; | ||
} | ||
} | ||
return newBoard; | ||
} | ||
static boolean isValid(int nx, int ny){ | ||
return 0 <= nx && nx < n && 0 <= ny && ny < n; | ||
} | ||
} |
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.