-
Notifications
You must be signed in to change notification settings - Fork 4
[13주차] 배수빈 #182
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
[13주차] 배수빈 #182
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
51ea9f7
배수빈: [BOJ] 1194 달이 차오른다, 가자._241203
baexxbin 8a844ba
배수빈: [SQL] 5월 식품들의 총매출 조회하기_241203
baexxbin 9ee7a11
배수빈: [BOJ] 8979 올림픽_241204
baexxbin e90ff09
배수빈: [BOJ] 1749 점수 따먹기_241205
baexxbin 4a9fc9b
배수빈: [BOJ] 150367 표현 가능한 이진트리_241206
baexxbin 13c2cb7
배수빈: [PG] 250135 아날로그 시계_241206
baexxbin a7fc347
배수빈: [CT] 술래잡기 체스_241206
baexxbin 5ab0fed
배수빈: [SQL] Movie Rating_241206
baexxbin 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
100 changes: 100 additions & 0 deletions
BOJ/1000-5000번/SB_1194.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,100 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class SB_1194 { | ||
static int N, M; | ||
static char[][] board; | ||
static Node start; | ||
static int ans = Integer.MAX_VALUE; | ||
static int[][][] visited; | ||
static int[] dx = {-1, 1, 0, 0}; | ||
static int[] dy = {0, 0, -1, 1}; | ||
|
||
private static void bfs() { | ||
Queue<Node> que = new ArrayDeque<>(); | ||
visited[start.x][start.y][0] = 0; | ||
que.offer(new Node(start.x, start.y, 0)); | ||
|
||
while (!que.isEmpty()) { | ||
Node cur = que.poll(); | ||
|
||
if (board[cur.x][cur.y] == '1') { | ||
ans = Math.min(ans, visited[cur.x][cur.y][cur.keys]); | ||
continue; | ||
} | ||
|
||
for (int i = 0; i < 4; i++) { | ||
int nx = cur.x + dx[i]; | ||
int ny = cur.y + dy[i]; | ||
int nk = cur.keys; | ||
if (!isValid(nx, ny) || board[nx][ny]=='#' || visited[nx][ny][nk]!=-1) continue; | ||
|
||
char nxt = board[nx][ny]; | ||
// 이동할 곳이 알파벳일 경우 | ||
if (Character.isAlphabetic(nxt)){ | ||
if (Character.isLowerCase(nxt)) nk |= (1 << (nxt - 'a')); // 키면 키 줍기 | ||
KodaHye marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else if (Character.isUpperCase(nxt)) { | ||
if ((nk & (1<< (nxt-'A')))==0) continue; // 키 없는 문은 못감 | ||
} | ||
} | ||
|
||
// 이동 가능할 경우 이동 | ||
que.offer(new Node(nx, ny, nk)); | ||
visited[nx][ny][nk] = visited[cur.x][cur.y][cur.keys] + 1; | ||
} | ||
} | ||
} | ||
|
||
private static boolean isValid(int x, int y) { | ||
return 0 <= x && x < N && 0 <= y && y < 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()); | ||
M = Integer.parseInt(st.nextToken()); | ||
|
||
board = new char[N][M]; | ||
visited = new int[N][M][1 << 6]; // 키 6개 존재 2^6 | ||
for (int i = 0; i < N; i++) { | ||
String line = br.readLine(); | ||
for (int j = 0; j < M; j++) { | ||
board[i][j] = line.charAt(j); | ||
if (board[i][j]=='0'){ | ||
start = new Node(i, j, 0); | ||
board[i][j] = '.'; | ||
} | ||
} | ||
} | ||
|
||
for (int i = 0; i < N; i++) { // 방문배열 초기화 | ||
for (int j = 0; j < M; j++) { | ||
Arrays.fill(visited[i][j], -1); | ||
} | ||
} | ||
|
||
bfs(); | ||
System.out.println(ans==Integer.MAX_VALUE ? -1 : ans); | ||
} | ||
static class Node{ | ||
int x, y, keys; | ||
|
||
public Node(int x, int y, int keys) { | ||
this.x = x; | ||
this.y = y; | ||
this.keys = keys; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Node{" + | ||
"x=" + x + | ||
", y=" + y + | ||
", keys=" + keys + | ||
'}'; | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
BOJ/1000-5000번/SB_1749.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,45 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_1749 { | ||
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 M = Integer.parseInt(st.nextToken()); | ||
|
||
int[][] board = new int[N][M]; | ||
long[][] dp = new long[N + 1][M + 1]; | ||
for (int i = 0; i < N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for (int j = 0; j < M; j++) { | ||
board[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
// 누적합 계산 | ||
for (int i = 1; i < N + 1; i++) { | ||
for (int j = 1; j < M + 1; j++) { | ||
dp[i][j] = board[i-1][j-1] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]; | ||
} | ||
} | ||
|
||
// 부분 행렬의 최대값 찾기 | ||
long mx = Long.MIN_VALUE; | ||
for (int r1 = 1; r1 < N + 1; r1++) { | ||
for (int c1 = 1; c1 <= M + 1; c1++) { | ||
for (int r2 = r1; r2 <= N; r2++) { | ||
for (int c2 = c1; c2 <= M; c2++) { | ||
long tmp = dp[r2][c2] - dp[r1 - 1][c2] - dp[r2][c1 - 1] + dp[r1 - 1][c1 - 1]; | ||
mx = Math.max(mx, tmp); | ||
} | ||
} | ||
} | ||
} | ||
|
||
System.out.println(mx); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
BOJ/5001-10000번/SB_8979.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,65 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class SB_8979 { | ||
static int N, K; | ||
static List<Nation> nations = new ArrayList<>(); | ||
private static int medal2Int(int g, int s, int b){ | ||
return g * 1000000 + s * 1000 + b; | ||
} | ||
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()); | ||
|
||
for (int i = 0; i < N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int idx = Integer.parseInt(st.nextToken()); | ||
int g = Integer.parseInt(st.nextToken()); | ||
int s = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
nations.add(new Nation(idx, medal2Int(g, s, b))); | ||
} | ||
|
||
Collections.sort(nations); | ||
|
||
int rank = 1; | ||
int tmp = 1; // 동점자 처리를 위한 변수(매번 증가) | ||
int preScore = nations.get(0).score; | ||
for (Nation cur : nations) { | ||
if (cur.score != preScore) rank = tmp; // 서로 점수가 다르면 순위 갱신 | ||
if (cur.idx==K){ // 찾는 나라면 순위 출력 | ||
System.out.println(rank); | ||
return; | ||
} | ||
tmp++; | ||
preScore = cur.score; | ||
} | ||
} | ||
|
||
static class Nation implements Comparable<Nation>{ | ||
int idx, score; | ||
|
||
public Nation(int idx, int score) { | ||
this.idx = idx; | ||
this.score = score; | ||
} | ||
|
||
@Override | ||
public int compareTo(Nation o) { | ||
return o.score - this.score; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Nation{" + | ||
"idx=" + idx + | ||
", score=" + score + | ||
'}'; | ||
} | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
CodeTree/2019-2020년/SB_술래잡기_체스.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,142 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class SB_술래잡기_체스 { | ||
static int mx = -1; | ||
static int[] dx = {-1, -1, 0, 1, 1, 1, 0, -1}; | ||
static int[] dy = {0, -1, -1, -1, 0, 1, 1, 1}; | ||
|
||
private static int[][] copyBoard(int[][] board) { | ||
int[][] tmp = new int[4][4]; | ||
for (int i = 0; i < 4; i++) { | ||
for (int j = 0; j < 4; j++) { | ||
tmp[i][j] = board[i][j]; | ||
} | ||
} | ||
return tmp; | ||
} | ||
|
||
private static List<Piece> copyPiece(List<Piece> pieces) { | ||
List<Piece> tmpList = new ArrayList<>(); | ||
for (Piece p : pieces) { | ||
tmpList.add(new Piece(p.idx, p.x, p.y, p.dir, p.isDie)); | ||
} | ||
return tmpList; | ||
} | ||
private static void dfs(Tagger it, int[][] board, List<Piece> pieces) { | ||
// 도둑말들 움직이기 | ||
moveThief(board, pieces); | ||
|
||
// 현재 방향으로 잡을 수 있는 말 잡기(최대 3번 이동 가능) | ||
for (int i = 1; i < 4; i++) { | ||
int nx = it.x + dx[it.dir] * i; | ||
int ny = it.y + dy[it.dir] * i; | ||
|
||
if (isValid(nx, ny) && board[nx][ny] != 0) { | ||
int[][] tmpBoard = copyBoard(board); | ||
List<Piece> tmpPiece = copyPiece(pieces); | ||
|
||
tmpBoard[it.x][it.y] = 0; | ||
Piece thief = tmpPiece.get(board[nx][ny]); | ||
Tagger nit = new Tagger(thief.x, thief.y, thief.dir, it.cnt + thief.idx); | ||
thief.isDie = true; | ||
tmpBoard[thief.x][thief.y] = -1; | ||
|
||
dfs(nit, tmpBoard, tmpPiece); | ||
} | ||
} | ||
mx = Math.max(mx, it.cnt); | ||
} | ||
|
||
|
||
private static void moveThief(int[][] board, List<Piece> pieces) { | ||
for (Piece cur : pieces) { | ||
if (cur.idx == 0 || cur.isDie) continue; // 죽었거나 술래면 스킵 | ||
for (int d = 0; d < 8; d++) { | ||
int nd = (cur.dir + d) % 8; | ||
int nx = cur.x + dx[nd]; | ||
int ny = cur.y + dy[nd]; | ||
if (!isValid(nx, ny) || board[nx][ny] == -1) continue; | ||
board[cur.x][cur.y] = 0; | ||
if (board[nx][ny] == 0) cur.setPos(nx, ny); // 빈칸이면 바로 이동 | ||
else { // 다른말있으면 교환 | ||
Piece target = pieces.get(board[nx][ny]); | ||
target.setPos(cur.x, cur.y); | ||
board[cur.x][cur.y] = target.idx; | ||
cur.setPos(nx, ny); | ||
} | ||
board[nx][ny] = cur.idx; // 움직일 보드에 현재 말 놓기 | ||
cur.dir = nd; // 현재 말의 방향 갱신 | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private static boolean isValid(int x, int y) { | ||
return 0 <= x && x < 4 && 0 <= y && y < 4; | ||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
int[][] board = new int[4][4]; // 말들의 번호로 저장 | ||
List<Piece> pieces = new ArrayList<>(); | ||
|
||
for (int i = 0; i < 4; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for (int j = 0; j < 4; j++) { | ||
int num = Integer.parseInt(st.nextToken()); | ||
int dir = Integer.parseInt(st.nextToken()) - 1; | ||
Piece piece = new Piece(num, i, j, dir, false); | ||
pieces.add(piece); | ||
board[i][j] = num; | ||
} | ||
} | ||
|
||
// 도둑말 인덱스 순으로 정렬 | ||
pieces.add(new Piece(0, -1, -1, 0, false)); // 인덱스 0맞추기 위해 더미 객체 넣기 | ||
pieces.sort(((o1, o2) -> o1.idx - o2.idx)); | ||
|
||
// 초기 0,0 도둑말 잡기 | ||
Piece first = pieces.get(board[0][0]); | ||
Tagger tagger = new Tagger(0, 0, first.dir, first.idx); | ||
board[0][0] = -1; | ||
first.isDie = true; | ||
|
||
// 술래말의 재귀 시작 | ||
dfs(tagger, board, pieces); | ||
|
||
System.out.println(mx); | ||
} | ||
|
||
static class Tagger{ | ||
int x, y, dir, cnt; | ||
|
||
public Tagger(int x, int y, int dir, int cnt) { | ||
this.x = x; | ||
this.y = y; | ||
this.dir = dir; | ||
this.cnt = cnt; | ||
} | ||
} | ||
|
||
static class Piece{ | ||
int idx, x, y, dir; | ||
boolean isDie; | ||
|
||
public Piece(int idx, int x, int y, int dir, boolean isDie) { | ||
this.idx = idx; | ||
this.x = x; | ||
this.y = y; | ||
this.dir = dir; | ||
this.isDie = isDie; | ||
} | ||
|
||
private void setPos(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
} | ||
} |
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.