diff --git "a/BOJ/1000-5000353円262円210円/JY_1135.java" "b/BOJ/1000-5000353円262円210円/JY_1135.java" new file mode 100644 index 00000000..df1f0410 --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/JY_1135.java" @@ -0,0 +1,59 @@ +package dfs; +import java.io.*; +import java.util.*; + +public class JY_1135 { + + static int N; + static List[] 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 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; + } +} diff --git "a/BOJ/1000-5000353円262円210円/JY_1450.java" "b/BOJ/1000-5000353円262円210円/JY_1450.java" new file mode 100644 index 00000000..013022a7 --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/JY_1450.java" @@ -0,0 +1,71 @@ +import java.io.*; +import java.util.*; +public class JY_1450 { + + static int N, C; + static int[] arr; + static List left; + static List 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(); + 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 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; + } + +} diff --git "a/BOJ/15001-20000353円262円210円/JY_19237.java" "b/BOJ/15001-20000353円262円210円/JY_19237.java" new file mode 100644 index 00000000..41b6c068 --- /dev/null +++ "b/BOJ/15001-20000353円262円210円/JY_19237.java" @@ -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 1000) System.out.println(-1); + else System.out.println(time); + + } + // -------- print + public static void printG(int[][] a) { + for(int i=0; i=0 && x=0 && y 자신의 냄새가 있는 칸으로 결정 + 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; + } + } + + // 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 0) { + g[i][j]--; + } + if(t[i][j]> 0) { + g[i][j] = t[i][j]; + } + } + } + } + public static boolean checkShark() { + for(int i=2; i q; + static boolean[][] visited; + static List pList; + static int fCnt; + static boolean isOk; + + static class State implements Comparable { + int x, y; + int degree, cnt; + int[][] sg; + + public State(int x, int y, int degree, int score, int[][] sg) { + super(); + this.x = x; + this.y = y; + this.degree = degree; + this.cnt = score; + this.sg = sg; + } + + // 획득가치큰거 -> 각도작은거 -> 열작은거-> 행작은거 + @Override + public int compareTo(State other) { + if(this.cnt == other.cnt) { + if(this.degree == other.degree) { + if(this.y == other.y) { + return this.x - other.x; + } + return this.y - other.y; + } + return this.degree - other.degree; + } + return other.cnt - this.cnt; + } + + @Override + public String toString() { + return "State [x=" + x + ", y=" + y + ", degree=" + degree + ", score=" + cnt + ", sg=" + + Arrays.toString(sg) + "]"; + } + + + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + K = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + g = new int[N][N]; + for(int i=0; i(); + st = new StringTokenizer(br.readLine()); + for(int i=0; i=0 && x=0 && y 각도작은거 -> 열작은거-> 행작은거 + public static int findSpot() { + PriorityQueue pq = new PriorityQueue(); + + for(int i=1; i(); + for(int i=0; i q = new LinkedList(); + q.add(new int[] {x, y}); + List tList = new ArrayList(); + tList.add(new int[] {x, y}); + int num = t[x][y]; + + while(!q.isEmpty()) { + int[] now = q.poll(); + + for(int i=0; i<4; i++) { + int nx = now[0] + dx[i]; + int ny = now[1] + dy[i]; + if(!inRange(nx, ny)) continue; + if(visited[nx][ny]) continue; + if(num != t[nx][ny]) continue; + + visited[nx][ny] = true; + tList.add(new int[] {nx, ny}); + q.add(new int[] {nx, ny}); + } + } + + if(tList.size()>= 3) { + pList.addAll(tList); + } + + } + public static void fillSpot() { + // 작은 열 -> 큰 행 + for(int j=0; j=0; i--) { + if(g[i][j] == 0) { + g[i][j] = q.poll(); + } + } + } + } + + +} diff --git a/Programmers/Level2/JY_389479.java b/Programmers/Level2/JY_389479.java new file mode 100644 index 00000000..a2749660 --- /dev/null +++ b/Programmers/Level2/JY_389479.java @@ -0,0 +1,36 @@ +class JY_389479 { + public int solution(int[] players, int m, int k) { + int answer = 0; + int P = players.length; + int[] crr = new int[P+k+1]; + + int cnt = 0; + int s = 0; + int e = 0; + for(int i=0; i= ((cnt+1)*m)) { + s = i; + e = s + k; + + // 추가해야할 서버 개수 + int nc = (p / m) - cnt; + crr[e] += nc; // 추가한 서버들이 끝나는 시간에 개수 저장 + cnt += nc; // 서버 추가 증설 + + answer += nc; // 증설 횟수 카운트 + } + + } + + + return answer; + } +} \ No newline at end of file diff --git "a/SQL/23354円243円274円354円260円250円/JY_352円267円270円353円243円271円353円263円204円_354円241円260円352円261円264円354円227円220円_353円247円236円353円212円224円_354円213円235円353円213円271円_353円252円251円353円241円235円_354円266円234円353円240円245円355円225円230円352円270円260円.sql" "b/SQL/23354円243円274円354円260円250円/JY_352円267円270円353円243円271円353円263円204円_354円241円260円352円261円264円354円227円220円_353円247円236円353円212円224円_354円213円235円353円213円271円_353円252円251円353円241円235円_354円266円234円353円240円245円355円225円230円352円270円260円.sql" new file mode 100644 index 00000000..9c2dc06d --- /dev/null +++ "b/SQL/23354円243円274円354円260円250円/JY_352円267円270円353円243円271円353円263円204円_354円241円260円352円261円264円354円227円220円_353円247円236円353円212円224円_354円213円235円353円213円271円_353円252円251円353円241円235円_354円266円234円353円240円245円355円225円230円352円270円260円.sql" @@ -0,0 +1,18 @@ +-- 그룹별 조건에 맞는 식당 목록 출력하기 +-- https://school.programmers.co.kr/learn/courses/30/lessons/131124 + +WITH BEST_REVIEWER AS ( + SELECT MEMBER_ID + FROM REST_REVIEW + GROUP BY MEMBER_ID + ORDER BY COUNT(MEMBER_ID) DESC + LIMIT 1 +) + +SELECT M.MEMBER_NAME, R.REVIEW_TEXT + , DATE_FORMAT(REVIEW_DATE, "%Y-%m-%d") AS REVIEW_DATE +FROM MEMBER_PROFILE M +JOIN REST_REVIEW R +ON M.MEMBER_ID = R.MEMBER_ID +WHERE M.MEMBER_ID = (SELECT * FROM BEST_REVIEWER) +ORDER BY R.REVIEW_DATE, R.REVIEW_TEXT \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /