-
Notifications
You must be signed in to change notification settings - Fork 4
[17주차] 배수빈 #234
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
[17주차] 배수빈 #234
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
338d3e0
배수빈: [BOJ] 3109 빵집_250107
baexxbin 871f00e
배수빈: [SQL] Managers with at Least 5 Direct Reports_250507
baexxbin b826a79
배수빈: [PG] 86052 빛의 경로 사이클_250108
baexxbin 2db29c1
배수빈: [PG] 12905 가장 큰 정사각형 찾기_250110
baexxbin f91f4f7
배수빈: [SQL] Sales Analysis III_250110
baexxbin d2509eb
배수빈: [BOJ] 20061 모노미노도미노 2_250110
baexxbin 13cf769
배수빈: [PG] 258711 도넛과 막대그래프_250111
baexxbin d864011
배수빈: [BOJ] 1765 닭싸움 팀정하기_250112
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
81 changes: 81 additions & 0 deletions
BOJ/1000-5000번/SB_1765.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,81 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_1765 { | ||
static int N, M; | ||
static int[] team, enemy; | ||
|
||
private static int find(int x) { | ||
if (team[x]!=x) team[x] = find(team[x]); | ||
return team[x]; | ||
} | ||
|
||
private static void union(int a, int b) { | ||
int pa = find(a); | ||
int pb = find(b); | ||
if (pa < pb) team[pb] = pa; | ||
else if (pb < pa) team[pa] = pb; | ||
} | ||
|
||
private static void makeRelation(char op, int p, int q) { | ||
int pp = find(p); | ||
int pq = find(q); | ||
|
||
if (pp == pq) return; | ||
|
||
if (op=='F'){ // 친구일 경우 팀 병합 | ||
union(pp, pq); | ||
|
||
// 팀 병합에 따른 원수 관계 병합 | ||
if (enemy[pp] != 0 && enemy[pq] != 0) union(enemy[pp], enemy[pq]); // 두 팀 모두 원수가 있으면 각 원수들끼리 친구 시키기 | ||
|
||
// 한 쪽만 원수 있으면 같이 원수 만들기 | ||
else if (enemy[pp]!=0) enemy[pq] = find(enemy[pp]); | ||
else if(enemy[pq]!=0) enemy[pp] = find(enemy[pq]); | ||
} | ||
else { // 원수일 경우, 각 팀의 원수를 상대랑 친구시키기 | ||
if (enemy[pp]==0) enemy[pp] = pq; // pp의 원수가 없으면 pp의 원수는 바로 pq의 원수가 됨 | ||
else union(enemy[pp], pq); // pp의 원수가 있으면 pp의 원수랑 pq랑 친구가 됨 | ||
|
||
if (enemy[pq]==0) enemy[pq] = pp; // 원수가 없으면 상대의 원수를 같이 원수로 받아드리고 | ||
else union(enemy[pq], pp); // 원수가 있으면 나의 원수와 상대가 친구가됨 | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
N = Integer.parseInt(br.readLine()); | ||
M = Integer.parseInt(br.readLine()); | ||
|
||
// 팀 초기화 | ||
team = new int[N + 1]; | ||
for (int i = 0; i < N + 1; i++) { | ||
team[i] = i; | ||
} | ||
enemy = new int[N + 1]; | ||
|
||
for (int i = 0; i < M; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
char op = st.nextToken().charAt(0); | ||
int p = Integer.parseInt(st.nextToken()); | ||
int q = Integer.parseInt(st.nextToken()); | ||
|
||
makeRelation(op, p, q); | ||
} | ||
|
||
|
||
// 부모 재정비 | ||
for (int i = 1; i <= N; i++) find(i); | ||
|
||
Set<Integer> ans = new HashSet<>(); | ||
for (int i = 1; i < N + 1; i++) { | ||
ans.add(find(i)); | ||
} | ||
System.out.println(ans.size()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
BOJ/1000-5000번/SB_3109.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,50 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_3109 { | ||
static int R, C; | ||
static char[][] board; | ||
static boolean[][] visited; | ||
static int[] dx = {-1, 0, 1}; | ||
static int[] dy = {1, 1, 1}; | ||
|
||
private static boolean backtracking(int r, int c) { | ||
if (c == C - 1) return true; | ||
|
||
for (int i = 0; i < 3; i++) { | ||
int nr = r + dx[i]; | ||
int nc = c + dy[i]; | ||
if (!isValid(nr, nc) || board[nr][nc]=='x' || visited[nr][nc]) continue; | ||
visited[nr][nc] = true; | ||
if (backtracking(nr, nc)) return true; // 그냥 함수값을 바로 리턴하면 실패했을때 더 못돌아봄 | ||
} | ||
return false; | ||
} | ||
|
||
private static boolean isValid(int x, int y) { | ||
return 0 <= x && x < R && 0 <= y && y < C; | ||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
R = Integer.parseInt(st.nextToken()); | ||
C = Integer.parseInt(st.nextToken()); | ||
|
||
board = new char[R][C]; | ||
visited = new boolean[R][C]; | ||
for (int i = 0; i < R; i++) { | ||
String line = br.readLine(); | ||
for (int j = 0; j < C; j++) { | ||
board[i][j] = line.charAt(j); | ||
} | ||
} | ||
|
||
int ans = 0; | ||
for (int r = 0; r < R; r++) { | ||
if(backtracking(r, 0)) ans++; | ||
} | ||
System.out.println(ans); | ||
} | ||
} |
256 changes: 256 additions & 0 deletions
BOJ/20001-25000번/SB_20061.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,256 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_20061 { | ||
static boolean[][] bBoard = new boolean[4][6]; | ||
static boolean[][] gBoard = new boolean[6][4]; | ||
static int ans = 0; | ||
|
||
private static void putBlueBlock(Block b) { | ||
// 행 고정, 열 움직이기 | ||
int targetCol = -1; | ||
for (int c = 0; c < 6; c++) { | ||
boolean canPlace = true; | ||
for (int i = 0; i < b.sr; i++) { // 블럭의 세로 크기만큼 확인 | ||
for (int j = 0; j < b.sc; j++) { // 블럭의 가로 크기만큼 확인 | ||
if (c + j > 5 || bBoard[b.r + i][c + j]) { // 블럭을 놓을 수 없을 경우(범위 벗어나거나 겹침) | ||
canPlace = false; | ||
break; | ||
} | ||
} | ||
if (!canPlace) break; // 현재 행 불가능이면 끝 | ||
} | ||
|
||
if (canPlace) targetCol = c; // 현재 위치가 블록을 놓을 수 있으면 targetCol 최신 현재 위치로 업데이트 | ||
else break; // 블록을 더이상 못놓으면 탈출 | ||
} | ||
|
||
// 블록을 targetCol에 놓기 | ||
if (targetCol != -1) { | ||
for (int i = 0; i < b.sr; i++) { | ||
for (int j = 0; j < b.sc; j++) { | ||
bBoard[b.r + i][targetCol + j] = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static void putGreenBlock(Block b) { | ||
// 열 고정, 행 움직이기 | ||
int targetRow = -1; | ||
for (int r = 0; r < 6; r++) { | ||
boolean canPlace = true; | ||
for (int i = 0; i < b.sr; i++) { | ||
for (int j = 0; j < b.sc; j++) { | ||
if (r + i > 5 || gBoard[r + i][b.c + j]) { | ||
canPlace = false; | ||
break; | ||
} | ||
} | ||
if (!canPlace) break; | ||
} | ||
if (canPlace) targetRow = r; | ||
else break; | ||
} | ||
|
||
if (targetRow != -1) { | ||
for (int i = 0; i < b.sr; i++) { | ||
for (int j = 0; j < b.sc; j++) { | ||
gBoard[targetRow + i][b.c + j] = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static int removeBlock() { // 꽉찬 행, 열 터치기 | ||
int score = 0; | ||
|
||
// 파란보드 (열 지우기) | ||
for (int c = 5; c >= 0; c--) { | ||
if (isColFull(c)) { | ||
removeCol(c); | ||
c++; // 열 제거후 이전 열이 지워진 열로 이동하기에, 같은열 다시 확인 | ||
score++; | ||
} | ||
} | ||
|
||
// 초록보드 (행 지우기) | ||
for (int r = 5; r >= 0; r--) { | ||
if (isRowFull(r)) { | ||
removeRow(r); | ||
r++; | ||
score++; | ||
} | ||
} | ||
|
||
return score; | ||
} | ||
|
||
private static boolean isColFull(int c) { | ||
for (int r = 0; r < 4; r++) { | ||
if (!bBoard[r][c]) return false; | ||
} | ||
return true; | ||
} | ||
|
||
private static void removeCol(int c) { | ||
// 터질 열을 기준으로 왼쪽에서 한열씩 이동 | ||
for (int j = c; j >0; j--) { | ||
for (int i = 0; i < 4; i++) { | ||
bBoard[i][j] = bBoard[i][j-1]; | ||
} | ||
} | ||
|
||
// 제일 끝 열(0열) 새 열로 초기화 | ||
for (int r = 0; r < 4; r++) { | ||
bBoard[r][0] = false; | ||
} | ||
} | ||
|
||
|
||
private static boolean isRowFull(int r) { | ||
for (int c = 0; c < 4; c++) { | ||
if (!gBoard[r][c]) return false; | ||
} | ||
return true; | ||
} | ||
|
||
private static void removeRow(int r) { | ||
// 터질 행 위에서 아래로 한 행씩 이동 | ||
for (int i = r; i > 0; i--) { | ||
for (int j = 0; j < 4; j++) { | ||
gBoard[i][j] = gBoard[i - 1][j]; | ||
} | ||
} | ||
|
||
// 제일 처음 행(0행) 초기화 | ||
for (int c = 0; c < 4; c++) { | ||
gBoard[0][c] = false; | ||
} | ||
} | ||
|
||
private static void pushLight() { | ||
// 연한 파랑 처리 | ||
int cnt1 = 0; | ||
for (int c = 0; c < 2; c++) { | ||
for (int r = 0; r < 4; r++) { | ||
if (bBoard[r][c]) { | ||
cnt1++; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
while (cnt1-- > 0) { | ||
removeCol(5); | ||
} | ||
|
||
|
||
// 연한 초록 처리 | ||
int cnt2 = 0; | ||
for (int r = 0; r < 2; r++) { | ||
for (int c = 0; c < 4; c++) { | ||
if (gBoard[r][c]) { | ||
cnt2++; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
while (cnt2-- > 0) { | ||
removeRow(5); | ||
} | ||
} | ||
|
||
private static int calBlock() { | ||
int cnt = 0; | ||
|
||
// 파란 보드 값 세기 | ||
for (int i = 0; i < 4; i++) { | ||
for (int j = 0; j < 6; j++) { | ||
if(bBoard[i][j]) cnt++; | ||
} | ||
} | ||
|
||
// 초록 보드 값 세기 | ||
for (int i = 0; i < 6; i++) { | ||
for (int j = 0; j < 4; j++) { | ||
if(gBoard[i][j]) cnt++; | ||
} | ||
} | ||
return cnt; | ||
} | ||
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()); | ||
while (N-- > 0) { | ||
st = new StringTokenizer(br.readLine()); | ||
int t = Integer.parseInt(st.nextToken()); | ||
int x = Integer.parseInt(st.nextToken()); | ||
int y = Integer.parseInt(st.nextToken()); | ||
|
||
Block block = new Block(x, y, t); | ||
|
||
// 블럭 놓기 | ||
putBlueBlock(block); | ||
putGreenBlock(block); | ||
|
||
// 타일 가득찬 블록 없애기 | ||
ans += removeBlock(); | ||
|
||
// 연한 칸 블록 처리 | ||
pushLight(); | ||
} | ||
|
||
// 점수 계산 | ||
sb.append(ans).append('\n').append(calBlock()); | ||
System.out.println(sb); | ||
} | ||
|
||
static private void print(boolean[][] board) { | ||
StringBuilder sb = new StringBuilder(); | ||
for (boolean[] b : board) { | ||
sb.append(Arrays.toString(b)).append('\n'); | ||
} | ||
System.out.println(sb); | ||
} | ||
|
||
static class Block{ | ||
int r, c, sr, sc; // 좌표 위치, 블럭 사이즈 | ||
|
||
public Block(int r, int c, int type) { | ||
this.r = r; | ||
this.c = c; | ||
switch (type) { | ||
case 1: | ||
this.sr = 1; | ||
this.sc = 1; | ||
break; | ||
case 2: | ||
this.sr = 1; | ||
this.sc = 2; | ||
break; | ||
case 3: | ||
this.sr = 2; | ||
this.sc = 1; | ||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Block{" + | ||
"r=" + r + | ||
", c=" + c + | ||
", sr=" + sr + | ||
", sc=" + sc + | ||
'}'; | ||
} | ||
} | ||
} |
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.