-
Notifications
You must be signed in to change notification settings - Fork 4
[3주차] 배수빈 #31
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
[3주차] 배수빈 #31
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6083b3c
배수빈: [CT] 디버깅_240923
baexxbin 90ed4ce
배수빈: [BOJ] 15989 1, 2, 3 더하기 4_240924
baexxbin 888b41a
배수빈: [SQL] 우유와 요거트가 담긴 장바구니_240924
baexxbin aa241b2
배수빈: [BOJ] 18404 현명한 나이트_240925
baexxbin b8da845
배수빈: [BOJ] 13335 트럭_240925
baexxbin 92171b0
배수빈: [SQL] 연간 평가점수에 해당하는 평가 등급 및 성과금 조회하기_240926
baexxbin e504d55
배수빈: [PG] 43236 징검다리_240926
baexxbin 8064d6e
배수빈: [CT] 나무 타이쿤_240927
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
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,55 @@ | ||
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_13335 { | ||
static int N, W, L; | ||
static int[] trucks; | ||
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()); | ||
W = Integer.parseInt(st.nextToken()); // 다리 길이 | ||
L = Integer.parseInt(st.nextToken()); // 다리 최대하중 | ||
|
||
trucks = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
trucks[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
Queue<Truck> que = new ArrayDeque<>(); | ||
que.offer(new Truck(trucks[0], 1)); | ||
|
||
int weight = trucks[0]; | ||
int time = 1; | ||
int idx = 1; | ||
while (!que.isEmpty()) { | ||
time++; | ||
|
||
if (time - que.peek().inTime == W) | ||
weight -= que.poll().w; | ||
|
||
if (idx < N && weight + trucks[idx] <= L && que.size() < W) { // 다리에 트럭추가 가능 시 | ||
que.offer(new Truck(trucks[idx], time)); | ||
weight += trucks[idx]; | ||
idx++; | ||
} | ||
} | ||
System.out.println(time); | ||
|
||
} | ||
static class Truck{ | ||
int w; | ||
int inTime; | ||
|
||
Truck(int w, int inTime) { | ||
this.w = w; | ||
this.inTime = inTime; | ||
} | ||
} | ||
} |
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,43 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
|
||
// 1, 2, 3 더하기 4 | ||
|
||
public class SB_15989 { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int T = Integer.parseInt(br.readLine()); | ||
|
||
int[] nums = new int[T]; | ||
int mx = -1; | ||
for (int i = 0; i < T; i++) { | ||
nums[i] = Integer.parseInt(br.readLine()); | ||
if (nums[i] > mx) mx = nums[i]; | ||
} | ||
|
||
int[][] dp = new int[4][mx + 1]; | ||
|
||
Arrays.fill(dp[1], 1); | ||
dp[1][0] = 0; | ||
|
||
for (int i = 2; i <= 3; i++) { | ||
for (int j = i; j <= mx; j++) { | ||
if (i==j) { | ||
dp[i][j] = 1; | ||
continue; | ||
} | ||
for (int k = i; k > 0; k--) { | ||
dp[i][j] += dp[k][j-i]; | ||
} | ||
} | ||
} | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
for (int n : nums) { | ||
sb.append(dp[1][n] + dp[2][n] + dp[3][n]).append('\n'); | ||
} | ||
System.out.println(sb); | ||
} | ||
} |
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.ArrayDeque; | ||
import java.util.Arrays; | ||
import java.util.Queue; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_18404 { | ||
static int N, M; | ||
static int[][] board; | ||
static int[] caught; | ||
static int[] dx = {-2, -2, -1, -1, 1, 1, 2, 2, 2}; | ||
static int[] dy = {-1, 1, -2, 2, -2, 2, -1, 1}; | ||
|
||
private static void bfs(int x, int y) { | ||
Queue<Node> que = new ArrayDeque<>(); | ||
int[][] visited = new int[N+1][N+1]; | ||
for (int[] row : visited){ | ||
Arrays.fill(row, -1); | ||
} | ||
visited[x][y] = 0; | ||
que.offer(new Node(x, y)); | ||
|
||
int cnt = 0; | ||
while (!que.isEmpty()){ | ||
Node knit = que.poll(); | ||
if (board[knit.x][knit.y] > 0) { | ||
caught[board[knit.x][knit.y]] = visited[knit.x][knit.y]; | ||
cnt++; | ||
} | ||
if (cnt==M) break; | ||
|
||
for (int i = 0; i < 8; i++) { | ||
int nx = knit.x + dx[i]; | ||
int ny = knit.y + dy[i]; | ||
if (!(0<nx && nx<=N && 0<ny && ny<=N)) continue; | ||
if (visited[nx][ny]==-1){ | ||
que.offer(new Node(nx, ny)); | ||
visited[nx][ny] = visited[knit.x][knit.y] + 1; | ||
} | ||
} | ||
} | ||
} | ||
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+1][N+1]; | ||
caught = new int[M + 1]; | ||
st = new StringTokenizer(br.readLine()); | ||
int sx = Integer.parseInt(st.nextToken()); | ||
int sy = Integer.parseInt(st.nextToken()); | ||
|
||
int idx = 1; | ||
for (int i = 0; i < M; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int x = Integer.parseInt(st.nextToken()); | ||
int y = Integer.parseInt(st.nextToken()); | ||
board[x][y] = idx++; | ||
} | ||
|
||
bfs(sx, sy); | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 1; i <= M; i++) { | ||
sb.append(caught[i]).append(' '); | ||
} | ||
System.out.println(sb); | ||
} | ||
|
||
static class Node{ | ||
int x, y; | ||
|
||
Node(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
} | ||
} |
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,113 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
/* | ||
* i번째에 i가 가도록. dfs로 완전탐색 | ||
* * 가지치기 | ||
* - 사다리 옆에 있으면 못놓기(양옆 체크) | ||
* - 초기 올바르게 가는 행에는 놓지 말기 | ||
* * 구현 | ||
* - 사다리타기 함수 | ||
* - 사다리 놓기 함수 | ||
* */ | ||
public class SB_디버깅 { | ||
static int N, M, H; // 열(사람), 선 갯수, 행(취약점, 가로) | ||
static Node[][] board; | ||
static int ans = -1; | ||
|
||
private static boolean play() { | ||
for (int c = 0; c < N; c++) { // 사람 한명씩 사다리 탐 (열) | ||
int idx = c; | ||
int r = 0; // 행 | ||
while (r<H){ | ||
if (board[r][c].isRight) c++; | ||
else if (board[r][c].isLeft) c--; | ||
r++; | ||
} | ||
if (idx!=c) return false; | ||
} | ||
return true; | ||
} | ||
|
||
private static void addLine(int depth) { | ||
if (depth>3 || ans!=-1) return; | ||
|
||
for (int i = 0; i < H; i++) { | ||
for (int j = 0; j < N-1; j++) { | ||
// 사다릴 못놓으면 패쓰 | ||
if (board[i][j].isLeft || board[i][j].isRight) continue; // 사다리 존재하면 놓을 수 없음 | ||
if (j>0 && board[i][j-1].isLeft) continue; // 이웃 사다리 여부 확인(사다리 연속X) | ||
|
||
// 사다리 놓기 | ||
board[i][j].onRight(); | ||
board[i][j+1].onLeft(); | ||
|
||
// System.out.println("depth:"+depth +" i:"+ i +" j: "+j); | ||
if (play()) { | ||
ans = depth; | ||
board[i][j].offRight(); | ||
board[i][j+1].offLeft(); | ||
return; | ||
} | ||
addLine(depth + 1); // 성공 못했으면 현재 상태에서 사다리 하나 더 추가해보기 | ||
board[i][j].offRight(); // 사다리 되돌리기 | ||
board[i][j+1].offLeft(); | ||
} | ||
} | ||
} | ||
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()); | ||
H = Integer.parseInt(st.nextToken()); | ||
|
||
board = new Node[H][N]; | ||
for (int i = 0; i < H; i++) { | ||
for (int j = 0; j < N; j++) { | ||
board[i][j] = new Node(i, j); | ||
} | ||
} | ||
|
||
for (int i = 0; i < M; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int a = Integer.parseInt(st.nextToken()); | ||
int b = Integer.parseInt(st.nextToken()); | ||
board[a-1][b-1].onRight(); | ||
board[a-1][b].onLeft(); | ||
} | ||
|
||
if (M==0 || play()) ans = 0; | ||
else addLine(1); | ||
|
||
System.out.println(ans); | ||
} | ||
|
||
static class Node{ | ||
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. 사다리 상태를 객체의 메소드로 관리하니 훨씬 깔끔하고 직관적으로 확인할 수 있는 것 같아요! 👍 다음에 참고해보고 싶어요~! |
||
int i; | ||
int j; | ||
boolean isLeft = false; | ||
boolean isRight = false; | ||
|
||
Node(int i, int j) { | ||
this.i = i; | ||
this.j = j; | ||
} | ||
|
||
public void onLeft(){ | ||
this.isLeft = true; | ||
} | ||
public void onRight(){ | ||
this.isRight = true; | ||
} | ||
public void offLeft(){ | ||
this.isLeft = false; | ||
} | ||
public void offRight(){ | ||
this.isRight = false; | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하!,, 저는 트럭을
ArrayList
에 담아서 시간이 갈 수록 각 트럭의 길이을+1
로 해준다음트럭이 간 길이 == 다리 길이
가 될 때poll
하는 걸로 했는데,time - 트럭이 터널에 들어간 시간 == W
을 조건으로 해주면 되는군요 ?!?! 😲제 시간이 다른 분들 시간이 좀 더 걸린 이유가 있었네요,,,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
흑 저도 처음엔
트럭이 간길이==다리길이
로 풀었는데 잘 안풀리더라구요...ㅠ 이방법 코드도 다시 한번 확인해봐야겠어요!!