-
Notifications
You must be signed in to change notification settings - Fork 4
[23주차] 이지영 #313
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
[23주차] 이지영 #313
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4c000e1
이지영: [CT] 고대 문명 유적 탐사_250217
yeongleej 4a56094
이지영: [BOJ] 19237번 어른상어_250218
yeongleej 851f5ed
이지영: [BOJ] 1135 뉴스 전하기_250219
yeongleej a98c3b5
이지영: [SQL] 그룹별 조건에 맞는 식당 목록 출력하기_250219
yeongleej 57c3109
이지영: [PG] 389479 서버 증설 횟수_250220
yeongleej da32cc7
이지영: [BOJ] 1450 냅색문제_250223
yeongleej 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
59 changes: 59 additions & 0 deletions
BOJ/1000-5000번/JY_1135.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,59 @@ | ||
package dfs; | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_1135 { | ||
|
||
static int N; | ||
static List<Integer>[] g; | ||
static int[] time; | ||
|
||
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()); | ||
g = new ArrayList[N]; | ||
|
||
for (int i = 0; i < N; i++) { | ||
g[i] = new ArrayList<>(); | ||
} | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
int p = Integer.parseInt(st.nextToken()); | ||
if (p != -1) { | ||
g[p].add(i); | ||
} | ||
} | ||
|
||
// 최소 시간 계산 | ||
System.out.println(dfs(0)); | ||
} | ||
|
||
public static int dfs(int node) { | ||
// 리프노드이면 전달시간 0 반환 | ||
if (g[node].isEmpty()) { | ||
return 0; | ||
} | ||
|
||
|
||
List<Integer> tList = new ArrayList<>(); | ||
|
||
// 내 자식에게 전파할 수 있는 총 시간 구하기 | ||
for (int child : g[node]) { | ||
tList.add(dfs(child)); | ||
} | ||
|
||
// 전파 시간이 긴 순으로 정렬 | ||
Collections.sort(tList, (o1, o2)-> o2-o1); | ||
|
||
int maxTime = 0; | ||
for (int i = 0; i < tList.size(); i++) { | ||
// 순차적으로 전화를 걸면서, 현재 전화받은 자식 기준으로 시간 계산 | ||
maxTime = Math.max(maxTime, tList.get(i) + i + 1); | ||
} | ||
|
||
return maxTime; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
BOJ/1000-5000번/JY_1450.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,71 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
public class JY_1450 { | ||
|
||
static int N, C; | ||
static int[] arr; | ||
static List<Integer> left; | ||
static List<Integer> right; | ||
|
||
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()); | ||
C = Integer.parseInt(st.nextToken()); | ||
|
||
arr = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
for(int i=0; i<N; i++) { | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
// 왼쪽, 오른쪽 부분 집합 구하기 | ||
left = new ArrayList<>(); | ||
right = new ArrayList<>(); | ||
comb(left, 0, N/2, 0); | ||
comb(right, N/2, N, 0); | ||
|
||
// 오른쪽 부분합 정렬 | ||
Collections.sort(right); | ||
|
||
int cnt = 0; | ||
int idx = 0; | ||
for(int i=0; i<left.size(); i++) { | ||
idx = bs(0, right.size()-1, left.get(i)); | ||
cnt += (idx+1); | ||
} | ||
|
||
System.out.println(cnt); | ||
|
||
|
||
} | ||
public static void comb(List<Integer> cList, int s, int e, int sum) { | ||
// 최대 무게 C보다 크면 return | ||
if(sum > C) return; | ||
// 모두 탐색 | ||
if(s == e) { | ||
cList.add(sum); | ||
return; | ||
} | ||
|
||
// s번째 포함 X | ||
comb(cList, s+1, e, sum); | ||
// s번째 포함 O | ||
comb(cList, s+1, e, sum+arr[s]); | ||
} | ||
public static int bs(int s, int e, int a) { | ||
int ans = 0; | ||
while(s <= e) { | ||
int mid = (s + e) / 2; | ||
if(right.get(mid) <= C - a) { | ||
ans = mid; | ||
s = mid + 1; | ||
} else { | ||
e = mid - 1; | ||
} | ||
} | ||
return ans; | ||
} | ||
|
||
} |
191 changes: 191 additions & 0 deletions
BOJ/15001-20000번/JY_19237.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,191 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class JY_19237 { | ||
|
||
static int N, M, K; | ||
static int[][] g; | ||
static int[][] t; | ||
static int[][][] drr; | ||
static Shark[] srr; | ||
static int[][] visited; | ||
// 상 하 좌 우 | ||
static int[] dx = {0, -1, 1, 0, 0}; | ||
static int[] dy = {0, 0, 0, -1, 1}; | ||
static boolean[] isDied; | ||
static class Shark { | ||
int num, x, y, dir; | ||
|
||
public Shark(int num, int x, int y, int dir) { | ||
super(); | ||
this.num = num; | ||
this.x = x; | ||
this.y = y; | ||
this.dir = dir; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Shark [num=" + num + ", x=" + x + ", y=" + y + ", dir=" + dir + "]"; | ||
} | ||
|
||
} | ||
|
||
|
||
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()); | ||
K = Integer.parseInt(st.nextToken()); | ||
|
||
g = new int[N][N]; // 냄새카운트 | ||
visited = new int[N][N]; // 상어 경로 | ||
srr = new Shark[M+1]; | ||
for(int i=0; i<N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for(int j=0; j<N; j++) { | ||
g[i][j] = Integer.parseInt(st.nextToken()); | ||
if(g[i][j] != 0) { | ||
srr[g[i][j]] = new Shark(g[i][j], i, j, 0); | ||
visited[i][j] = g[i][j]; | ||
g[i][j] = K; | ||
} | ||
} | ||
} | ||
|
||
// 상어 초기 방향 | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for(int i=1; i<M+1; i++) { | ||
srr[i].dir = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
// 상어 우선순위 배열 | ||
drr = new int[M+1][5][5]; | ||
for(int i=1; i<M+1; i++) { | ||
for(int j=1; j<5; j++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for(int k=1; k<5; k++) { | ||
drr[i][j][k] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
isDied = new boolean[M+1]; | ||
int time = 1; | ||
|
||
while(time <= 1000) { | ||
// 1) 상어 이동(동시에!) | ||
moveShark(); | ||
|
||
// 2) 냄새 처리 | ||
spreadSmell(); | ||
|
||
// 3) 남은 상어 체크 | ||
if(checkShark()) break; | ||
|
||
time++; | ||
|
||
} | ||
if(time > 1000) System.out.println(-1); | ||
else System.out.println(time); | ||
|
||
} | ||
public static void printG(int[][] a) { | ||
for(int i=0; i<N; i++) { | ||
System.out.println(Arrays.toString(a[i])); | ||
} | ||
System.out.println(); | ||
} | ||
public static void printD(int[][][] a) { | ||
for(int i=1; i<a.length; i++) { | ||
// 상어 | ||
System.out.println("num: "+i); | ||
for(int j=0; j<a[0].length; j++) { | ||
System.out.println(Arrays.toString(a[i][j])+" "); | ||
} | ||
System.out.println(); | ||
} | ||
System.out.println(); | ||
} | ||
// -------------- | ||
|
||
public static boolean inRange(int x, int y) { | ||
return x>=0 && x<N && y>=0 && y<N; | ||
} | ||
public static void moveShark() { | ||
t = new int[N][N]; | ||
|
||
// 상어 반복 | ||
for(int i=1; i<M+1; i++) { | ||
if(isDied[i]) continue; | ||
Shark now = srr[i]; | ||
|
||
// 1-1) 4방향 중 냄새 없는 칸 찾기 | ||
int nDir = -1; | ||
for(int d=1; d<5; d++) { | ||
int dir = drr[i][now.dir][d]; | ||
int nx = now.x + dx[dir]; | ||
int ny = now.y + dy[dir]; | ||
if(!inRange(nx, ny)) continue; | ||
if(g[nx][ny] != 0) continue; | ||
nDir = dir; | ||
break; | ||
} | ||
|
||
// 1-2) 냄새없는 칸없음 -> 자신의 냄새가 있는 칸으로 결정 | ||
if(nDir == -1) { | ||
for(int d=1; d<5; d++) { | ||
int dir = drr[i][now.dir][d]; | ||
int nx = now.x + dx[dir]; | ||
int ny = now.y + dy[dir]; | ||
if(!inRange(nx, ny)) continue; | ||
if(visited[nx][ny] != now.num) continue; | ||
nDir = dir; | ||
break; | ||
} | ||
} | ||
jewan100 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 2) 가장 우선순위 높은 방향으로 상어이동 | ||
now.x += dx[nDir]; | ||
now.y += dy[nDir]; | ||
now.dir = nDir; | ||
|
||
// 이동한 곳에 번호가 낮은 다른 상어가 있음 -> 쫒겨남 | ||
if(t[now.x][now.y] != 0) { | ||
isDied[i] = true; | ||
} | ||
else { | ||
visited[now.x][now.y] = now.num; | ||
t[now.x][now.y] = K; | ||
} | ||
|
||
} | ||
} | ||
public static void spreadSmell() { | ||
// 원본배열 냄새는 -1 | ||
// 새로운 배열 냄새 반영 | ||
for(int i=0; i<N; i++) { | ||
for(int j=0; j<N; j++) { | ||
if(g[i][j] > 0) { | ||
g[i][j]--; | ||
} | ||
if(t[i][j] > 0) { | ||
g[i][j] = t[i][j]; | ||
} | ||
} | ||
} | ||
} | ||
public static boolean checkShark() { | ||
for(int i=2; i<M+1; i++) { | ||
if(!isDied[i]) return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
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.