From de7516b3140bfd8e72ef30ff0319170e8220efab Mon Sep 17 00:00:00 2001 From: yeahdy Date: Mon, 7 Oct 2024 21:23:29 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[CT]=20=EB=86=80=EC=9D=B4=EA=B8=B0=EA=B5=AC?= =?UTF-8?q?=20=ED=83=91=EC=8A=B9=5F241007?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\265\254_\355\203\221\354\212\271.java" | 151 ++++++++++++++++++ Programmers/Level3/YJ_42898.java | 29 ++++ 2 files changed, 180 insertions(+) create mode 100644 "CodeTree/2021-2022\353\205\204/YJ_\353\206\200\354\235\264\352\270\260\352\265\254_\355\203\221\354\212\271.java" create mode 100644 Programmers/Level3/YJ_42898.java diff --git "a/CodeTree/2021-2022\353\205\204/YJ_\353\206\200\354\235\264\352\270\260\352\265\254_\355\203\221\354\212\271.java" "b/CodeTree/2021-2022\353\205\204/YJ_\353\206\200\354\235\264\352\270\260\352\265\254_\355\203\221\354\212\271.java" new file mode 100644 index 00000000..fd3d1a56 --- /dev/null +++ "b/CodeTree/2021-2022\353\205\204/YJ_\353\206\200\354\235\264\352\270\260\352\265\254_\355\203\221\354\212\271.java" @@ -0,0 +1,151 @@ +import java.util.*; +import java.io.*; + +class Student { + int x; + int y; + int likeCount; + int blanckCount; + + public Student(int x, int y, int likeCount, int blanckCount){ + this.x=x; + this.y=y; + this.likeCount=likeCount; + this.blanckCount=blanckCount; + } + + public boolean isBestPosition(Student best){ + //1. 4방향 탐색 "좋아하는 친구"의 수가 가장 많은 위치로 이동 + if(this.likeCount != best.likeCount){ + return this.likeCount > 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 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 getScore(friendCount); + } + + private static int getScore(int friendCount){ + switch (friendCount){ + case 1: + return 1; + case 2: + return 10; + case 3: + return 100; + case 4: + return 1000; + } + return 0; + } + + 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/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]; + } +} From 0d3f9267a3b93edce0be5d02f9402c404b4d76b9 Mon Sep 17 00:00:00 2001 From: yeahdy Date: Tue, 8 Oct 2024 17:45:50 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[SQL]=20=EC=8B=9D=ED=92=88=EB=B6=84?= =?UTF-8?q?=EB=A5=98=EB=B3=84=20=EA=B0=80=EC=9E=A5=20=EB=B9=84=EC=8B=BC=20?= =?UTF-8?q?=EC=8B=9D=ED=92=88=EC=9D=98=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=98=EA=B8=B0=5F241008?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\241\260\355\232\214\355\225\230\352\270\260.sql" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "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" 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; From b15690521d2bd381f6b5b868ce6e5a54157b3826 Mon Sep 17 00:00:00 2001 From: yeahdy Date: Tue, 8 Oct 2024 21:36:52 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[CT]=20=EC=A0=84=EC=9E=90=EC=82=AC=EC=A0=84?= =?UTF-8?q?=20=EB=A7=8C=EB=93=A4=EA=B8=B0=5F241008?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\247\214\353\223\244\352\270\260.java" | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 "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" 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..d795e91b --- /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 List original = new ArrayList<>(); + 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; + } +} From b67c5c76aead8094dc203e6a745b6a1c71816af8 Mon Sep 17 00:00:00 2001 From: yeahdy Date: Tue, 8 Oct 2024 21:46:22 +0900 Subject: [PATCH 4/8] =?UTF-8?q?refactor:=20[CT]=20=EC=A0=84=EC=9E=90?= =?UTF-8?q?=EC=82=AC=EC=A0=84=20=EB=A7=8C=EB=93=A4=EA=B8=B0=5F241008?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 시간 단축 --- ...4\354\240\204_\353\247\214\353\223\244\352\270\260.java" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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" index d795e91b..e990cbad 100644 --- "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" @@ -6,7 +6,7 @@ * 시간복잡도: 1 ≤ N ≤ 100,000 → 10^5 으로 `O(NlogN)` 이내로 풀이하기 */ public class YJ_전자사전_만들기 { - static List original = new ArrayList<>(); + 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)); @@ -18,7 +18,7 @@ public static void main(String[] args) throws IOException { for(int i=0; i Date: Wed, 9 Oct 2024 20:10:26 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[BOJ]=201967=20=ED=8A=B8=EB=A6=AC=EC=9D=98?= =?UTF-8?q?=20=EC=A7=80=EB=A6=84=5F241009?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/1000-5000\353\262\210/YJ_1967.java" | 86 ++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "BOJ/1000-5000\353\262\210/YJ_1967.java" 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 Date: Wed, 9 Oct 2024 20:21:21 +0900 Subject: [PATCH 6/8] =?UTF-8?q?refactor:=20[CT]=20=EB=86=80=EC=9D=B4?= =?UTF-8?q?=EA=B8=B0=EA=B5=AC=20=ED=83=91=EC=8A=B9=5F241007?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 약 10ms 시간단축 --- ...0\352\265\254_\355\203\221\354\212\271.java" | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git "a/CodeTree/2021-2022\353\205\204/YJ_\353\206\200\354\235\264\352\270\260\352\265\254_\355\203\221\354\212\271.java" "b/CodeTree/2021-2022\353\205\204/YJ_\353\206\200\354\235\264\352\270\260\352\265\254_\355\203\221\354\212\271.java" index fd3d1a56..d0548582 100644 --- "a/CodeTree/2021-2022\353\205\204/YJ_\353\206\200\354\235\264\352\270\260\352\265\254_\355\203\221\354\212\271.java" +++ "b/CodeTree/2021-2022\353\205\204/YJ_\353\206\200\354\235\264\352\270\260\352\265\254_\355\203\221\354\212\271.java" @@ -115,6 +115,7 @@ else if(likes.contains(ride[x][y])){ 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]); @@ -128,21 +129,7 @@ static int calculateScore(int currentX, int currentY){ friendCount++; } } - return getScore(friendCount); - } - - private static int getScore(int friendCount){ - switch (friendCount){ - case 1: - return 1; - case 2: - return 10; - case 3: - return 100; - case 4: - return 1000; - } - return 0; + return scoreBoard[friendCount]; } private static boolean stop(int x, int y){ From a4c26620aca42eb22921a9bfed713cb9ccdca1d6 Mon Sep 17 00:00:00 2001 From: yeahdy Date: Thu, 10 Oct 2024 13:29:36 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[PG]=2042885=20=EC=83=81=EB=8B=B4=EC=9B=90?= =?UTF-8?q?=20=EC=9D=B8=EC=9B=90=5F214288?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level3/YJ_214288.java | 100 ++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Programmers/Level3/YJ_214288.java 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)); + } + +} + From 39db8c45b53ac9fdc967f2e7ce5b0d1a769468ef Mon Sep 17 00:00:00 2001 From: yeahdy Date: Sat, 12 Oct 2024 19:22:02 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[BOJ]=209205=20=EB=A7=A5=EC=A3=BC=20?= =?UTF-8?q?=EB=A7=88=EC=8B=9C=EB=A9=B4=EC=84=9C=20=EA=B1=B8=EC=96=B4?= =?UTF-8?q?=EA=B0=80=EA=B8=B0=5F241011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/5001-10000\353\262\210/YJ_9205.java" | 81 +++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "BOJ/5001-10000\353\262\210/YJ_9205.java" diff --git "a/BOJ/5001-10000\353\262\210/YJ_9205.java" "b/BOJ/5001-10000\353\262\210/YJ_9205.java" new file mode 100644 index 00000000..4d7d56ce --- /dev/null +++ "b/BOJ/5001-10000\353\262\210/YJ_9205.java" @@ -0,0 +1,81 @@ +package BOJ; + +import java.io.*; +import java.util.ArrayDeque; +import java.util.Deque; + +/** + * 알고리즘: BFS + * 시간복잡도: + * 테스트 케이스 t ≤ 50 , 편의점 갯수 0 ≤ n ≤ 100 + * 모든 지점 간의 거리 계산 시 N * (N-1) = O(N^2) > 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