diff --git "a/BOJ/1000-5000\353\262\210/YJ_1967.java" "b/BOJ/1000-5000\353\262\210/YJ_1967.java" new file mode 100644 index 00000000..538717fa --- /dev/null +++ "b/BOJ/1000-5000\353\262\210/YJ_1967.java" @@ -0,0 +1,86 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +/** + * 알고리즘: DFS + * 시간복잡도: 1 ≤ n ≤ 10,000 + * 아이디어: + * 트리에 존재하는 모든 경로들 중에서 가장 긴 것의 길이 구하기 + * DFS 1번: 루트에서 가장 멀리 있는 노드 탐색 (루트는 항상 존재하기 때문에 루트에서 시작) + * DFS 2번: 해당 노드에서 가장 먼 노드 탐색 > 가장 긴 길이 계산 + */ + +class Node { + int node; + int weight; + + public Node(int node, int weight) { + this.node = node; + this.weight = weight; + } +} + +public class YJ_1967 { + static List[] TREE = null; + static boolean[] VISITED = null; + static int FAR_NODE = 0; + static int longLength = 0; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + VISITED = new boolean[N+1]; + + //List index 가 하나의 노드 단위 + TREE = new ArrayList[N+1]; + for(int i=1; i(); + } + + //트리 생성 + for(int i=1; i 50 * (100^2) = 50 * 10000 = 500,000 > 10^5 으로 BFS 풀이가능 + * */ +public class YJ_9205 { + static class Pos { + int x; + int y; + Pos(int x, int y) { + this.x = x; + this.y = y; + } + } + + static Deque DEQUE; + static int[][] CONVINI; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(br.readLine()); + + for(int i=0; i(); + DEQUE.offer(new Pos(Integer.parseInt(home[0]), Integer.parseInt(home[1]))); + //편의점 + CONVINI = new int[conviniCount][2]; + for(int j=0; j best.likeCount; + } + //2. 4방향을 탐색해서 비어있는 위치 카운팅 + else if(this.blanckCount != best.blanckCount){ + return this.blanckCount > best.blanckCount; + } + //3. 그 중 행 번호가 가장 작은 위치로 이동 + else if(this.x != best.x){ + return this.x < best.x; + } + //4. 그 중 열 번호가 가장 작은 위치로 이동 + return this.y < best.y; + } + +} + +public class YJ_놀이기구_탑승 { + static int[] numbers; //학생들 번호 + static Map> likeStudents = new HashMap<>(); //학생별 좋아하는 번호 + static int[][] ride; //놀이기구 탑승 + static int n=0; + static int TOTAL=0; + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + n = Integer.parseInt(br.readLine()); + ride = new int[n][n]; + TOTAL = n*n; + numbers = new int[TOTAL]; + + //입력값 초기화 + for(int i=0; i likes = new ArrayList<>(); + for(int j=0; j<4; j++){ + likes.add(Integer.parseInt(line[j+1])); + } + likeStudents.put(numbers[i],likes); + } + + for(int i=0; i likes){ + Student best = new Student(n,n,-1,-1); + for(int i=0; i likes, int currentX, int currentY){ + int blanckCount=0; + int likeCount=0; + + for(int i=0; i<4; i++){ + int x = currentX + nx[i]; + int y = currentY + ny[i]; + + if(stop(x,y)){ + continue; + } + //2.비어있는 위치 카운팅 + if(ride[x][y] == 0){ + blanckCount++; + } + //1.좋아하는 친구 수 카운팅 + else if(likes.contains(ride[x][y])){ + likeCount++; + } + } + return new Student(currentX,currentY,likeCount,blanckCount); + } + + static int[] scoreBoard = {0,1,10,100,1000}; + static int calculateScore(int currentX, int currentY){ + int friendCount = 0; + List likes = likeStudents.get(ride[currentX][currentY]); + for(int p=0; p<4; p++){ + int x = currentX + nx[p]; + int y = currentY + ny[p]; + if(stop(x,y)){ + continue; + } + if(likes.contains(ride[x][y])){ + friendCount++; + } + } + return scoreBoard[friendCount]; + } + + private static boolean stop(int x, int y){ + return x < 0 || x >= n || y < 0 || y >= n; + } +} \ No newline at end of file diff --git "a/CodeTree/2023-2024\353\205\204/YJ_\354\240\204\354\236\220\354\202\254\354\240\204_\353\247\214\353\223\244\352\270\260.java" "b/CodeTree/2023-2024\353\205\204/YJ_\354\240\204\354\236\220\354\202\254\354\240\204_\353\247\214\353\223\244\352\270\260.java" new file mode 100644 index 00000000..e990cbad --- /dev/null +++ "b/CodeTree/2023-2024\353\205\204/YJ_\354\240\204\354\236\220\354\202\254\354\240\204_\353\247\214\353\223\244\352\270\260.java" @@ -0,0 +1,111 @@ +import java.util.*; +import java.io.*; + +/** + * 알고리즘: 이분탐색 + * 시간복잡도: 1 ≤ N ≤ 100,000 → 10^5 으로 `O(NlogN)` 이내로 풀이하기 + */ +public class YJ_전자사전_만들기 { + static Map original = new HashMap<>(); + static String[] dictionary = null; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String[] line1 = br.readLine().split("\\s"); + int N = Integer.parseInt(line1[0]); + int T = Integer.parseInt(line1[1]); + + dictionary = new String[N]; + for(int i=0; i 0) { + right = mid-1; + } + //mid 값이 더 작을 경우 + else{ + left = mid+1; + } + } + return start; + } + + static int findEndSearch(String target){ + int left = 0; + int right = dictionary.length-1; + int end = 0; + + while(left <= right){ + int mid = (left+right)/2; + if(dictionary[mid].startsWith(target)){ + end = mid; + left = mid+1; + } + //mid 값이 더 클 경우 + else if (dictionary[mid].compareTo(target) > 0) { + right = mid-1; + } + //mid 값이 더 작을 경우 + else{ + left = mid+1; + } + } + return end; + } + + static String findWord(int start, int end, int k){ + if(end-start < k-1){ + return ""; + } + int j=0; + String target = ""; + for(int i=start; i<=end; i++){ + target = dictionary[i]; + if(k-1 == j){ + break; + } + j++; + } + return target; + } +} diff --git a/Programmers/Level3/YJ_214288.java b/Programmers/Level3/YJ_214288.java new file mode 100644 index 00000000..7015f232 --- /dev/null +++ b/Programmers/Level3/YJ_214288.java @@ -0,0 +1,100 @@ +import java.util.*; + +/** + * 알고리즘: PriorityQueue + 구현 + * 시간복잡도: 3 ≤ reqs의 길이 ≤ 300 으로 단순구현 가능 + * 아이디어: + - 유형별 최소 대기시간 계산에 따라 최적의 멘토 인원 분배 수를 찾고, 최소시간 계산하기 + - 유형별 멘토 인원 분배 방법 + - PriorityQueue를 사용해서 여러 작업에서 가장 빨리 완료할 수 있는 작업부터 처리하기 + - 여러 작업: 유형별 상담 요청 + - 가장 빨리 완료: 상담종료 시간이 가장 적은 사람부터 처리 + - 기다리는 시간을 계산하고, 상담 종료 시 다음 상담요청 배치 + */ +public class YJ_214288 { + static class Participant { + int startTime; + int endTime; + int counseling; + int type; + public Participant(int startTime, int counseling, int type) { + this.startTime = startTime; + this.endTime = startTime+counseling; + this.counseling = counseling; + this.type = type; + } + } + + static List participantList = new ArrayList<>(); + static int getTotalWaitingTime(int k, int n, int[][] reqs) { + for(int [] r : reqs){ + participantList.add(new Participant(r[0],r[1],r[2])); + } + + int[] typeMento = new int[k+1]; + Arrays.fill(typeMento,1); //유형별로 최소 1명의 상담원 배치 + int remainingMento = n-k; + + while(remainingMento > 0){ + int minTime = Integer.MAX_VALUE; + int bestDivision = -1; + //임의로 상담원을 배치해서 최적의 상담원 배치 도출하기 + for(int i=1; i pq = new PriorityQueue<>(); + int waitingTime = 0; + //유형별로 계산 + for(Participant participant : participantList){ + if(participant.type != type){ + continue; + } + if(pq.size() < typeMento[type]){ + pq.offer(participant.endTime); + continue; + } + + int minEndTime = pq.poll(); + //대기시간 계산: 최소 상담종료시간 - 현재 사람의 상담 시작시간 + waitingTime += Math.max(0,minEndTime-participant.startTime); + //현재 사람의 상담이 종료되는 가장 빠른 시간 + int fastEndTime = Math.max(minEndTime,participant.startTime)+participant.counseling; + pq.offer(fastEndTime); + } + + totalWaitingTime += waitingTime; + } + + return totalWaitingTime; + } + + public static void main(String[] args) { + int k = 3; + int n = 5; + int[][] reqs = {{10, 60, 1}, {15, 100, 3}, {20, 30, 1}, {30, 50, 3}, {50, 40, 1}, {60, 30, 2}, {65, 30, 1}, {70, 100, 2}}; + System.out.println(getTotalWaitingTime(k, n, reqs)); + } + +} + diff --git a/Programmers/Level3/YJ_42898.java b/Programmers/Level3/YJ_42898.java new file mode 100644 index 00000000..06b26f40 --- /dev/null +++ b/Programmers/Level3/YJ_42898.java @@ -0,0 +1,29 @@ +public class YJ_42898 { + int solution(int m, int n, int[][] puddles) { + int[][] dp = new int[n+1][m+1]; + final int CONDITION = 1000000007; + //물웅덩이 초기화 [1] x, [0] y + for(int i=0; i 0){ //위에서 오는 방향 + dp[i][j] = (dp[i-1][j]+dp[i][j]) % CONDITION; + } + if(dp[i][j-1] > 0){ //왼쪽에서 오는 방향 + dp[i][j] = (dp[i][j] + dp[i][j-1]) % CONDITION; + } + } + } + + return dp[n][m]; + } +} diff --git "a/SQL/05\354\243\274\354\260\250/YJ_\354\213\235\355\222\210\353\266\204\353\245\230\353\263\204 \352\260\200\354\236\245 \353\271\204\354\213\274 \354\213\235\355\222\210\354\235\230 \354\240\225\353\263\264 \354\241\260\355\232\214\355\225\230\352\270\260.sql" "b/SQL/05\354\243\274\354\260\250/YJ_\354\213\235\355\222\210\353\266\204\353\245\230\353\263\204 \352\260\200\354\236\245 \353\271\204\354\213\274 \354\213\235\355\222\210\354\235\230 \354\240\225\353\263\264 \354\241\260\355\232\214\355\225\230\352\270\260.sql" new file mode 100644 index 00000000..cc56c5fd --- /dev/null +++ "b/SQL/05\354\243\274\354\260\250/YJ_\354\213\235\355\222\210\353\266\204\353\245\230\353\263\204 \352\260\200\354\236\245 \353\271\204\354\213\274 \354\213\235\355\222\210\354\235\230 \354\240\225\353\263\264 \354\241\260\355\232\214\355\225\230\352\270\260.sql" @@ -0,0 +1,12 @@ +-- 식품분류가 '과자', '국', '김치', '식용유'인 경우만 출력 +-- 식품 가격을 기준으로 내림차순 정렬 +SELECT + fp.CATEGORY, fp.PRICE, fp.PRODUCT_NAME +FROM FOOD_PRODUCT fp + JOIN + (SELECT CATEGORY, MAX(PRICE) MAX_PRICE + FROM FOOD_PRODUCT + WHERE CATEGORY IN ('과자','국','김치','식용유') + GROUP BY CATEGORY) AS sub + ON fp.CATEGORY = sub.CATEGORY AND fp.PRICE = sub.MAX_PRICE +ORDER BY fp.PRICE DESC;