-
Notifications
You must be signed in to change notification settings - Fork 4
[10주차] 배수빈 #139
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
[10주차] 배수빈 #139
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
01b3d86
dosc: 10주차 리드미 업데이트
baexxbin 3908ef2
배수빈: [CT] 회전하는 빙하_241111
baexxbin 6fe2781
배수빈: [BOJ] 2096 내려가기_241113
baexxbin 064ddcf
배수빈: [BOJ] 1613 역사_241113
baexxbin 55abddc
배수빈: [PG] 150366 표 병합_241114
baexxbin cbf1e99
배수빈: [PG] 181188 요격 시스템_241115
baexxbin e81a503
배수빈: [PG] 42884 단속카메라_241115
baexxbin 5b85a0c
배수빈: [SQL] Students and Examinations_241115
baexxbin 9ba5059
배수빈: [SQL] 입양 시각 구하기(2)_241115
baexxbin 083e407
배수빈: [BOJ] 2955 스도쿠 풀기(틀린코드)_241116
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
56 changes: 56 additions & 0 deletions
BOJ/1000-5000번/SB_1613.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,56 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class SB_1613 { | ||
static int N, K; | ||
static int[][] order; | ||
static int INF = Integer.MAX_VALUE >> 2; | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
K = Integer.parseInt(st.nextToken()); | ||
|
||
order = new int[N + 1][N + 1]; | ||
for (int i = 1; i < N + 1; i++) { | ||
Arrays.fill(order[i], INF); | ||
order[i][i] = 0; | ||
} | ||
|
||
for (int i = 0; i < K; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int a = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
order[a][b] = 1; | ||
} | ||
|
||
for (int k = 1; k < N + 1; k++) { | ||
for (int i = 1; i < N + 1; i++) { | ||
for (int j = 1; j < N + 1; j++) { | ||
if (order[i][j] > order[i][k] + order[k][j]) { | ||
order[i][j] = order[i][k] + order[k][j]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
int S = Integer.parseInt(br.readLine()); | ||
while (S-- > 0) { | ||
st = new StringTokenizer(br.readLine()); | ||
int a = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
|
||
if (order[a][b] != INF) sb.append(-1); | ||
else if (order[b][a] != INF) sb.append(1); | ||
else sb.append(0); | ||
sb.append('\n'); | ||
} | ||
|
||
System.out.println(sb); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
BOJ/1000-5000번/SB_2096.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,54 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_2096 { | ||
static int N; | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
N = Integer.parseInt(br.readLine()); | ||
int[][] dpMx = new int[2][3]; // 이전값, 현재값 | ||
int[][] dpMn = new int[2][3]; | ||
|
||
st = new StringTokenizer(br.readLine()); // 초기 0행 값 설정 | ||
for (int i = 0; i < 3; i++) { | ||
int x = Integer.parseInt(st.nextToken()); | ||
dpMx[0][i] = x; | ||
dpMx[1][i] = x; | ||
dpMn[0][i] = x; | ||
dpMn[1][i] = x; | ||
} | ||
|
||
for (int i = 1; i < N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int a = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
int c = Integer.parseInt(st.nextToken()); | ||
|
||
dpMx[1][0] = Math.max(dpMx[0][0], dpMx[0][1]) + a; | ||
dpMx[1][1] = Math.max(dpMx[0][0], Math.max(dpMx[0][1], dpMx[0][2])) + b; | ||
dpMx[1][2] = Math.max(dpMx[0][1], dpMx[0][2]) + c; | ||
|
||
dpMn[1][0] = Math.min(dpMn[0][0], dpMn[0][1]) + a; | ||
dpMn[1][1] = Math.min(dpMn[0][0], Math.min(dpMn[0][1], dpMn[0][2])) + b; | ||
dpMn[1][2] = Math.min(dpMn[0][1], dpMn[0][2]) + c; | ||
|
||
// 이전값을 업데이트된 현재값 업데이트 | ||
dpMx[0][0] = dpMx[1][0]; | ||
dpMx[0][1] = dpMx[1][1]; | ||
dpMx[0][2] = dpMx[1][2]; | ||
|
||
dpMn[0][0] = dpMn[1][0]; | ||
dpMn[0][1] = dpMn[1][1]; | ||
dpMn[0][2] = dpMn[1][2]; | ||
} | ||
|
||
int mx = Math.max(dpMx[0][0], Math.max(dpMx[0][1], dpMx[0][2])); | ||
int mn = Math.min(dpMn[0][0], Math.min(dpMn[0][1], dpMn[0][2])); | ||
|
||
System.out.println(mx + " " + mn); | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
BOJ/1000-5000번/SB_2955.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,125 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class SB_2955 { | ||
static int[][] board = new int[9][9]; | ||
static boolean[][] row = new boolean[9][10]; | ||
static boolean[][] col = new boolean[9][10]; | ||
static boolean[][] box = new boolean[9][10]; | ||
|
||
|
||
private static boolean crossHatching(int num) { | ||
boolean flag = false; | ||
for (int i = 0; i < 9; i++) { // 가로줄 놓을 수 있는지 확인 | ||
int cr = -1, cc = -1, cnt = 0; | ||
for (int j = 0; j < 9; j++) { | ||
if (board[i][j] == 0 && !row[i][num] && !col[j][num] && !box[boxIdx(i, j)][num]) { | ||
cr = i; | ||
cc = j; | ||
cnt++; | ||
} | ||
} | ||
if (cnt == 1) { | ||
placeNumber(cr, cc, num); | ||
flag = true; | ||
} | ||
} | ||
|
||
for (int j = 0; j < 9; j++) { // 세로줄 놓을 수 있는지 확인 | ||
int cr = -1, cc = -1, cnt = 0; | ||
for (int i = 0; i < 9; i++) { | ||
if (board[i][j] == 0 && !row[i][num] && !col[j][num] && !box[boxIdx(i, j)][num]) { | ||
cr = i; | ||
cc = j; | ||
cnt++; | ||
} | ||
} | ||
if (cnt == 1) { | ||
placeNumber(cr, cc, num); | ||
flag = true; | ||
} | ||
} | ||
|
||
for (int idx = 0; idx < 9; idx++) { // 박스 놓을 수 있는지 확인 | ||
int cr = -1, cc = -1, cnt = 0; | ||
int sr = (idx / 3) * 3, sc = (idx % 3) * 3; | ||
for (int i = 0; i < 3; i++) { | ||
for (int j = 0; j < 3; j++) { | ||
int r = sr + i; | ||
int c = sc + j; | ||
if (board[r][c] == 0 && !row[r][num] && !col[c][num] && !box[idx][num]) { | ||
cr = r; | ||
cc = c; | ||
cnt++; | ||
} | ||
} | ||
} | ||
if (cnt == 1) { | ||
placeNumber(cr, cc, num); | ||
flag = true; | ||
} | ||
} | ||
return flag; | ||
} | ||
|
||
private static void placeNumber(int r, int c, int num) { | ||
board[r][c] = num; | ||
row[r][num] = true; | ||
col[c][num] = true; | ||
box[boxIdx(r, c)][num] = true; | ||
} | ||
|
||
private static int boxIdx(int i, int j) { | ||
return (i / 3) * 3 + j / 3; | ||
} | ||
|
||
private static void printBoard() { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int[] row : board) { | ||
for (int c : row) { | ||
sb.append(c == 0 ? "." : c); | ||
} | ||
sb.append("\n"); | ||
} | ||
System.out.print(sb); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
for (int i = 0; i < 9; i++) { | ||
String line = br.readLine(); | ||
for (int j = 0; j < 9; j++) { | ||
int num = line.charAt(j) == '.' ? 0 : line.charAt(j) - '0'; | ||
board[i][j] = num; | ||
if (num != 0) { | ||
if (row[i][num] || col[j][num] || box[boxIdx(i, j)][num]) { // 입력값이 잘못됐을 경우 에러 | ||
System.out.println("ERROR"); | ||
return; | ||
} | ||
row[i][num] = true; | ||
col[j][num] = true; | ||
box[boxIdx(i, j)][num] = true; | ||
} | ||
} | ||
} | ||
|
||
boolean doTry = false; // 첫 시도 체크 변수 | ||
boolean updated = true; // 숫자 적은거 있는지 체크 | ||
while (updated) { | ||
updated = false; | ||
for (int num = 1; num <= 9; num++) { | ||
boolean res = crossHatching(num); | ||
updated |= res; | ||
doTry |= res; | ||
} | ||
} | ||
|
||
if (!doTry){ // 아예 시도조차 못할 경우 에러 | ||
System.out.println("ERROR"); | ||
return; | ||
} | ||
|
||
printBoard(); | ||
} | ||
} |
159 changes: 159 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,159 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayDeque; | ||
import java.util.Queue; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_회전하는_빙하 { | ||
static int N, Q, M; | ||
static int[][] board; | ||
static boolean[][] visited; | ||
static int[] dx = {-1, 1, 0, 0}; | ||
static int[] dy = {0, 0, -1, 1}; | ||
static int area = 0; | ||
static int mx = 0; | ||
private static void bfs(int x, int y) { | ||
Queue<Node> que = new ArrayDeque<>(); | ||
que.offer(new Node(x, y)); | ||
visited[x][y] = true; | ||
|
||
int size = 0; | ||
while (!que.isEmpty()) { | ||
Node cur = que.poll(); | ||
area += board[cur.x][cur.y]; | ||
size++; | ||
|
||
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] || board[nx][ny]==0) continue; | ||
que.offer(new Node(nx, ny)); | ||
visited[nx][ny] = true; | ||
} | ||
} | ||
mx = Math.max(mx, size); | ||
} | ||
|
||
private static void calIceGroup() { | ||
visited = new boolean[M][M]; | ||
|
||
for (int i = 0; i < M; i++) { | ||
for (int j = 0; j < M; j++) { | ||
if (!visited[i][j] && board[i][j] > 0) { | ||
bfs(i, j); | ||
} | ||
} | ||
} | ||
} | ||
private static void meltIce() { | ||
boolean[][] check = new boolean[M][M]; | ||
|
||
// 녹을 빙하 체크 | ||
for (int i = 0; i < M; i++) { | ||
for (int j = 0; j < M; j++) { | ||
if (board[i][j]==0) continue; // 얼음이 아닌 곳은 패쓰 | ||
int cnt = 0; | ||
for (int k = 0; k < 4; k++) { | ||
int nx = i + dx[k]; | ||
int ny = j + dy[k]; | ||
if (isValid(nx, ny) && board[nx][ny]>0) cnt++; | ||
} | ||
if (cnt < 3) check[i][j] = true; | ||
} | ||
} | ||
|
||
// 체크된 빙하 녹이기 | ||
for (int i = 0; i < M; i++) { | ||
for (int j = 0; j < M; j++) { | ||
if (check[i][j]) board[i][j]--; | ||
} | ||
} | ||
} | ||
|
||
private static boolean isValid(int x, int y) { | ||
return 0<=x && x<M && 0<=y && y<M; | ||
} | ||
private static void rotateIce(int sx, int sy, int l, int[][] tmp) { // 레벨 사각형안의 분할된 사각형의 회전 | ||
int s = 1<<l; | ||
int ss = 1 << (l - 1); | ||
|
||
for (int i = sx; i < sx + s; i+=ss) { // 현재 레벨 사각형의 시작 꼭짓점부터 진행 | ||
for (int j = sy; j < sy + s; j+=ss) { | ||
int ox = i - sx; // 0점 맞추기 | ||
int oy = j - sy; | ||
int rx = oy; // 회전 좌표 | ||
int ry = s-ox-ss; | ||
for (int x = 0; x < ss; x++) { // 분할된 사각형 조각 이동 | ||
for (int y = 0; y < ss; y++) { | ||
int cx = i + x; // 원본 배열에서 현재 위치 | ||
int cy = j + y; | ||
int nx = rx + x; // 회전된 좌표에서 새로운 위치 | ||
int ny = ry + y; | ||
tmp[nx+sx][ny+sy] = board[cx][cy]; // 회전된 위치엔 보정으로 뺐던 시작값 더해주기 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
private static void rotate(int l) { | ||
int s = 1<<l; | ||
// tmp 배열 복사 | ||
int[][] tmp = new int[M][M]; | ||
for (int i = 0; i < M; i++) { | ||
for (int j = 0; j < M; j++) { | ||
tmp[i][j] = board[i][j]; | ||
} | ||
} | ||
|
||
// 큰 사각형 회전 (레벨 사각형) | ||
for (int i = 0; i < M; i+=s) { | ||
for (int j = 0; j < M; j+=s) { | ||
rotateIce(i, j, l, tmp); | ||
} | ||
} | ||
|
||
// 회전한 내용 반영 | ||
board = tmp; | ||
} | ||
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()); | ||
Q = Integer.parseInt(st.nextToken()); | ||
|
||
M = 1<<N; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 제곱근 연산을 Math.pow로 해서 계속 int로 형변환을 해줬는데요,,!! |
||
board = new int[M][M]; | ||
|
||
for (int i = 0; i < M; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for (int j = 0; j < M; j++) { | ||
board[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
// 회전 수행 | ||
st = new StringTokenizer(br.readLine()); | ||
while (Q-- > 0) { | ||
int L = Integer.parseInt(st.nextToken()); | ||
if (L > 0) rotate(L); | ||
meltIce(); // 얼음 녹기 | ||
} | ||
|
||
// 얼음군집 구하기 | ||
calIceGroup(); | ||
|
||
System.out.println(area); | ||
System.out.println(mx); | ||
} | ||
|
||
static class Node{ | ||
int x, y; | ||
|
||
public Node(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.