-
Notifications
You must be signed in to change notification settings - Fork 4
[1주차] 이예진 #6
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
[1주차] 이예진 #6
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6d047da
이예진: [SQL] 주문량이 많은 아이스크림들 조회하기_240912
yeahdy 6a9c1f8
이예진: [PG] 132265 롤케이크 자르기_240912
yeahdy 6472419
이예진: [PG] 12927 야근지수_240912
yeahdy 17c9c81
Merge branch 'main' of https://github.com/yeahdy/AlgorithmStudy
yeahdy b304352
이예진: [SQL] Frontend_개발자_찾기_240910
yeahdy 9f41d38
이예진: [PG] 154539 뒤에 있는 큰 수 찾기_240913
yeahdy 211b3a1
이예진: [PG] 154539 뒤에 있는 큰 수 찾기_240913
yeahdy cf33898
이예진: [PG] 132265 롤케이크 자르기_240912
yeahdy 00a4ff3
이예진: [BOJ] 2531 회전 초밥_240910
yeahdy 13892b5
이예진: [BOJ] 3020 개똥벌레_240911
yeahdy 51bb4af
이예진: [PG] 49994 방문길이_240913
yeahdy 3850dd7
이예진: [BOJ] 3020 개똥벌레_240911 주석 수정
yeahdy e144769
이예진: [SQL] 주석 설명 보완
yeahdy e9618f2
이예진: [PG] 49994 방문길이_240913 (BFS 구현)
yeahdy 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
69 changes: 69 additions & 0 deletions
BOJ/1000-10000번/YJ_2531.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,69 @@ | ||
import java.util.*; | ||
|
||
/** | ||
* 알고리즘: 투 포인터 | ||
* 시간복잡도: O(n) | ||
* 아이디어: | ||
* 처음 접시부터 마지막 접시까지의 하나의 회전을 하기 위해서 N-1번 회전이 필요 | ||
* 처음 접시부터 마지막 접시까지의 이어진 k 개의 연속된 묶음을 고려했을 때 횟수가 N-1 번 회전하기 때문 | ||
* N = 5, k = 3인 경우 | ||
* 1 2 | ||
* 0 3 | ||
* 4 | ||
* 초기 셋팅: [0, 1, 2] | ||
* 1번째 이동: [1, 2, 3] | ||
* 2번째 이동: [2, 3, 4] | ||
* 3번째 이동: [3, 4, 0] | ||
* 4번째 이동: [4, 0, 1] | ||
* | ||
* 회전을 반복할 때는 처음과 끝을 index를 기준으로 하나의 k 로 묶어서 확인해야함 | ||
*/ | ||
public class YJ_2531 { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
String[] first = sc.nextLine().split("\\s"); | ||
|
||
int N = Integer.parseInt(first[0]); //접시의 수 | ||
int d = Integer.parseInt(first[1]); //초밥의 가짓수 | ||
int k = Integer.parseInt(first[2]); //연속해서 먹는 접시의 수 | ||
int c = Integer.parseInt(first[3]); //쿠폰번호(=초밥종류) | ||
|
||
int[] belt = new int[N]; | ||
for(int i = 0 ; i < N ; i++) { | ||
belt[i] = Integer.parseInt(sc.nextLine()); | ||
} | ||
System.out.println(susiBelt(belt,N,d,k,c)); | ||
} | ||
|
||
static int susiBelt(int[] belt, int N, int d, int k, int c){ | ||
int[] susi = new int[d+1]; //먹은 초밥 종류 관련 배열 | ||
susi[c] = 3001; //무료 초밥 종류(최대 3000) | ||
|
||
int free = 1; | ||
for(int i=0;i<k;i++){ //초기셋팅: 회전초밥을 순회하며 다른 종류의 k 개의 초밥 담기 | ||
int idx = belt[i]; | ||
if(susi[idx]==0) //★belt[i]를 스시에 넣어서 회전초밥에서 중복된 초밥 종류를 공통적으로 처리 | ||
free++; | ||
susi[idx]++; | ||
} | ||
|
||
//★susi[i] 가 1일 경우 이미 먹음, 0일 경우 이미 먹었기 때문에 제외시킴 | ||
int max = free; | ||
for(int i = 0; i < N-1; i++) { //O(n) | ||
int start = belt[i]; | ||
int end = belt[((i+k) < N) ? (i+k) : (i+k) % N]; //★조합 묶음 +1 (== 마지막 접시 > 처음접시 회전) | ||
|
||
// 조합 묶음 +1번째 초밥을 처음 먹을 경우 | ||
if(++susi[end] == 1){ | ||
free++; | ||
} | ||
// 이미 먹은 초밥 제외 | ||
if(--susi[start] == 0){ | ||
free--; | ||
} | ||
max = Math.max(max, free); | ||
} | ||
return max; | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
BOJ/1000-10000번/YJ_3020.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,69 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
/** | ||
* 알고리즘: 이분탐색 | ||
* 시간복잡도: O(NlogN) | ||
* 아이디어: | ||
* 순서가 상관없다면 정렬을 활용하자 > 이분탐색 가능 | ||
* 이분탐색 사용가능 방법: 위 아래 각각 구분해서 동시에 전체를 탐색하기 | ||
*/ | ||
public class YJ_3020 { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
String[] first = br.readLine().split("\\s"); | ||
int N = Integer.parseInt(first[0]); //동굴길이 | ||
int H = Integer.parseInt(first[1]); //높이 | ||
|
||
int[] up = new int[N/2]; | ||
int[] down = new int[N/2]; | ||
for(int i=0; i<N/2; i++){ | ||
int downNum = Integer.parseInt(br.readLine()); | ||
int upNum = Integer.parseInt(br.readLine()); | ||
down[i] = downNum; | ||
up[i] = upNum; | ||
} | ||
|
||
System.out.println(destruction(N,H,up,down)); | ||
} | ||
|
||
static String destruction (int N, int H, int[] up, int[] down){ | ||
int minDestroy = N; //초기값은 최대값으로 설정 | ||
int spaceConut = 0; | ||
|
||
Arrays.sort(up); //O(NlogN) | ||
Arrays.sort(down); | ||
|
||
for(int i=1; i<H+1; i++){ //O(H) | ||
int destroy = binary(0,N/2,i,down) //★시작,끝,처음높이,아래장애물 | ||
+ binary(0,N/2,H-i+1,up); //★시작,끝,마지막높이,위장애물 | ||
|
||
//최소 구간 카운팅 | ||
if(destroy == minDestroy){ | ||
spaceConut++; | ||
continue; | ||
} | ||
//파괴한 최소값 갱신 | ||
if(destroy < minDestroy) { | ||
minDestroy = destroy; | ||
spaceConut = 1; | ||
} | ||
} | ||
return minDestroy + " " + spaceConut; | ||
} | ||
|
||
//down H: 1 2 3 4 5 6 7 | ||
//up H: 7 6 5 4 3 2 1 | ||
private static int binary(int left, int right, int current, int[] cave){ //O(logN) | ||
//찾는 값(H)이 중간 보다 클경우 중간 이하(왼쪽)의 값들 보다 무조건 큼 | ||
while(left < right){ | ||
int mid = (left + right)/2; | ||
if(cave[mid] >= current){ //★충돌 | ||
right = mid; //왼쪽으로 이동 | ||
} else { | ||
left = mid + 1; //오른쪽으로 이동 | ||
} | ||
} | ||
return cave.length-right; //충돌 수 | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
Programmers/Level2/YJ_뒤에_있는_큰_수_찾기.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,40 @@ | ||
import java.util.Stack; | ||
|
||
/** | ||
* 알고리즘: Stack | ||
* 시간복잡도: O(n) | ||
* 아이디어: | ||
* 전체에서 하나씩 더 큰수를 찾으며 비교하는게 아니라, | ||
* 전체 반복을 돌면서 기존 수과 다음에 오는 수를 계속해서 비교하는데 이때 이전에 누적된 수도 함께 갱신할 수 있어야한다. | ||
* 또한 배열에 담긴 수를 가져오기 위해 index 를 활용해서 Stack에 index를 담고 이전에 누적된 수를 가져오도록 한다 | ||
*/ | ||
public class YJ_뒤에_있는_큰_수_찾기 { | ||
public static void main(String[] args) { | ||
int[] numbers1 = {2, 3, 3, 5}; //3, 5, 5, -1 | ||
int[] numbers2 = {9, 1, 5, 3, 6, 2}; //-1, 5, 6, 6, -1, -1 | ||
int[] result = solution(numbers2); | ||
for (int j : result) { | ||
System.out.print(j + " "); | ||
} | ||
} | ||
|
||
static int[] solution(int[] numbers) { | ||
int n = numbers.length; | ||
|
||
Stack<Integer> stack = new Stack<>(); | ||
int i = 0; | ||
stack.push(i); | ||
for(i=1; i<n; i++){ //O(n) | ||
while(!stack.isEmpty() && numbers[stack.peek()] < numbers[i]){ //O(n) | ||
numbers[stack.pop()] = numbers[i]; | ||
} | ||
stack.push(i); | ||
} | ||
|
||
while(!stack.isEmpty()){ //O(n) | ||
numbers[stack.pop()] = -1; | ||
} | ||
|
||
return numbers; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
Programmers/Level2/YJ_롤케이크_자르기.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,45 @@ | ||
import java.util.HashSet; | ||
|
||
/** | ||
* 알고리즘: HashSet | ||
* 시간복잡도: O(n) | ||
* 아이디어: | ||
* 전체 토핑 수를 기준으로 철수와 동생이 각각 토핑을 가져간 수를 카운팅했을 때 | ||
* 철수(왼쪽) [1,2,2,3,3,4,4,4] | ||
* 동생(오른쪽) [4,4,4,4,3,3,2,1] | ||
* 철수가 왼쪽에서 토핑 하나를 가져갔을 때 동생은 오른쪽을 기준으로 +1 개까지만 토핑을 가져갈 수 있다 | ||
* (동생의 토핑수를 담은 배열 정렬은 뒤에서 부터 자름) | ||
* 따라서 n(철수) == n+1(동생) 이 같을 때 평등하게 토핑을 나눌 수 있다 | ||
*/ | ||
public class YJ_롤케이크_자르기 { | ||
public static void main(String[] args) { | ||
int[] topping = {1, 2, 1, 3, 1, 4, 1, 2}; | ||
System.out.println(solution(topping)); | ||
} | ||
|
||
static int solution(int[] topping) { | ||
int n = topping.length; | ||
HashSet<Integer> toppingSet = new HashSet<>(); //HashSet<토핑갯수> 토핑 중복제거 | ||
|
||
int[] left = new int[n]; | ||
for(int i=0; i<n; i++){ //O(n) | ||
toppingSet.add(topping[i]); | ||
left[i] = toppingSet.size(); | ||
} | ||
|
||
toppingSet.clear(); | ||
int[] right = new int[n]; | ||
for(int i=left.length-1; i>=0; i--){ //O(n) | ||
toppingSet.add(topping[i]); | ||
right[i] = toppingSet.size(); | ||
} | ||
|
||
int answer = 0; | ||
for(int i=0; i<n-1; i++){ //O(n) | ||
if(left[i] == right[i+1]){ | ||
answer++; | ||
} | ||
} | ||
return answer; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
Programmers/Level2/YJ_방문길이.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,70 @@ | ||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
|
||
/** | ||
* 알고리즘: BFS | ||
* 시간복잡도: O(n) | ||
* 아이디어: | ||
* BFS로 순회할때 방문한 지점을 방문처리 하는 것이 아닌 다녀간 길을 방문처리 해야 함 | ||
* 다녀간 길을 표시하는 방법? | ||
* | ||
*/ | ||
public class YJ_방문길이 { | ||
public static void main(String[] args) { | ||
String dirs = "ULURRDLLU"; //7 | ||
// String dirs = "LULLLLLLU"; //7 | ||
System.out.println(solution(dirs)); | ||
} | ||
|
||
static int answer = 0; | ||
static int[][] direction = {{0,1},{0,-1},{-1,0},{1,0}}; //상,하,좌,우 | ||
static boolean[][] visited = new boolean[11][11]; | ||
static Queue<int[]> queue = new LinkedList<>(); | ||
static int solution(String dirs) { | ||
String[] input = dirs.split(""); | ||
int[] start = {5,5}; | ||
int[] end = {11,11}; | ||
|
||
//현재위치 방문처리 | ||
queue.offer(start); | ||
visited[start[0]][start[1]] = true; | ||
|
||
for(String i : input){ | ||
switch(i){ | ||
case "U": | ||
bfs(visited,direction[0]); | ||
break; | ||
case "D": | ||
bfs(visited,direction[1]); | ||
break; | ||
case "L": | ||
bfs(visited,direction[2]); | ||
break; | ||
case "R": | ||
bfs(visited,direction[3]); | ||
break; | ||
} | ||
} | ||
return answer; | ||
} | ||
|
||
private static void bfs(boolean[][] visited, int[] direction){ | ||
int[] current = queue.peek(); | ||
//위치 이동 | ||
int nx = current[0] + direction[0]; | ||
int ny = current[1] + direction[1]; | ||
|
||
if(nx < 0 || nx > visited[0].length -1 || ny < 0 || ny > visited.length-1){ | ||
return; | ||
} | ||
if(visited[nx][ny]){ | ||
return; | ||
} | ||
//방문처리 | ||
queue.poll(); | ||
visited[nx][ny] = true; | ||
//이동값 갱신 | ||
queue.offer(new int[]{nx,ny}); | ||
answer++; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
Programmers/Level3/YJ_야근지수.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,12 @@ | ||
import java.util.HashSet; | ||
|
||
public class YJ_야근지수 { | ||
public static void main(String[] args) { | ||
int[] topping = {1, 2, 1, 3, 1, 4, 1, 2}; | ||
System.out.println(solution(topping)); | ||
} | ||
|
||
static int solution(int[] topping) { | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
SQL/1주차/YJ_FrontEnd 개발자 찾기.sql
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,17 @@ | ||
-- 문제: https://school.programmers.co.kr/learn/courses/30/lessons/276035 | ||
-- 요구사항: 개발자의 ID, 이메일, 이름, 성을 조회 + ID를 기준으로 오름차순 정렬 | ||
|
||
SELECT | ||
D.ID, D.EMAIL, D.FIRST_NAME, D.LAST_NAME | ||
FROM DEVELOPERS AS D | ||
INNER JOIN SKILLCODES AS S | ||
ON D.SKILL_CODE & S.CODE = S.CODE | ||
WHERE S.CATEGORY = 'Front End' | ||
GROUP BY D.ID, D.EMAIL, D.FIRST_NAME, D.LAST_NAME | ||
ORDER BY D.ID; | ||
|
||
-- 참고 | ||
-- 비트 AND연산 (10진수 & 10진수) | ||
-- 400 & 16 (110010000 & 10000) | ||
-- 결과: 16 (10000) | ||
-- SQL에서 비트연산자는 숫자를 2진수로 자동변환해서 연산하기 때문에 변환하지 않아도됨 |
18 changes: 18 additions & 0 deletions
SQL/1주차/YJ_주문량이_많은_아이스크림들_조회하기.sql
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,18 @@ | ||
-- 문제: https://school.programmers.co.kr/learn/courses/30/lessons/133027 | ||
-- 요구사항: 상위 3개 FLAVOR 맛별로 (7월 아이스크림 총 주문량+상반기의 아이스크림 총 주문량) | ||
SELECT | ||
JULY.FLAVOR | ||
FROM JULY | ||
INNER JOIN | ||
(SELECT | ||
FIRST_HALF.FLAVOR | ||
,FIRST_HALF.TOTAL_ORDER AS T_O | ||
FROM FIRST_HALF) AS FH | ||
ON JULY.FLAVOR = FH.FLAVOR | ||
GROUP BY FLAVOR | ||
ORDER BY SUM(JULY.TOTAL_ORDER+FH.T_O) DESC | ||
LIMIT 3; | ||
|
||
-- 참고 | ||
-- FIRST_HALF 테이블 PK: FLAVOR, FK: SHIPMENT_ID | ||
-- JULY 테이블 PK: SHIPMENT_ID FK: FLAVOR |
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.