-
Notifications
You must be signed in to change notification settings - Fork 4
[6주차] 이지영 #79
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
[6주차] 이지영 #79
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7eccea3
이지영: [CT] 테트리스 블럭 안의 합 최대화 하기_241014
yeongleej eff4a95
이지영: [BOJ] 2805 나무 자르기_241015
yeongleej 98a4ede
이지영: [BOJ] 2110 공유기 설치_241015
yeongleej 92c2344
이지영: [BOJ] 7579 앱_241016
yeongleej 9f0ae35
이지영: [BOJ] 9084 동전_241016
yeongleej 7627188
이지영: [PG] 43238 입국심사_241017
yeongleej 6356a27
이지영: [SQL] 대장균들의 자식의 수 구하기_241015
yeongleej 4d78dde
이지영: [SQL] 재구매가 일어난 상품과 회원 리스트 구하기_241017
yeongleej a4bb43b
이지영: [SQL] 주문량이 많은 아이스크림들 조회하기_241017
yeongleej 92855e8
이지영: [PG] 42861 섬 연결하기_241018
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
55 changes: 55 additions & 0 deletions
BOJ/1000-5000번/JY_2110.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,55 @@ | ||
package day1015; | ||
|
||
import java.util.*; | ||
import java.io.*; | ||
|
||
public class JY_2110 { | ||
|
||
static int N, C; | ||
static long[] wrr; | ||
|
||
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()); | ||
|
||
wrr = new long[N]; | ||
for(int i=0; i<N; i++) { | ||
wrr[i] = Long.parseLong(br.readLine()); | ||
} | ||
|
||
// 집위치 정렬 | ||
Arrays.sort(wrr); | ||
|
||
long s = 0; | ||
long e = (wrr[N-1] - wrr[0]); | ||
while(s < e) { | ||
// 인접한 두 공유기 사이의 거리 | ||
long mid = (s + e) / 2; | ||
|
||
long nextPos = 0; | ||
int cnt = 0; | ||
for(int i=0; i<N; i++) { | ||
// 공유기 새로 설치해야 함 | ||
if(wrr[i] >= nextPos) { | ||
nextPos = wrr[i] + mid; | ||
cnt++; | ||
} | ||
yeahdy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// 필요한 공유기수가 더 많거나 같으면 거리를 늘릴 수 있음 | ||
if(cnt >= C) { | ||
s = mid + 1; | ||
} | ||
// 필요한 공유기수가 더 작으면 거리를 좁혀야 함 | ||
else { | ||
e = mid; | ||
} | ||
} | ||
|
||
System.out.println(e); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
BOJ/1000-5000번/JY_2805.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,48 @@ | ||
package day1015; | ||
|
||
import java.util.*; | ||
import java.io.*; | ||
|
||
public class JY_2805 { | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int N = Integer.parseInt(st.nextToken()); | ||
int M = Integer.parseInt(st.nextToken()); | ||
|
||
int[] trr = new int[N]; | ||
int maxH = Integer.MIN_VALUE; | ||
st = new StringTokenizer(br.readLine()); | ||
for(int i=0; i<N; i++) { | ||
trr[i] = Integer.parseInt(st.nextToken()); | ||
maxH = Math.max(maxH, trr[i]); | ||
yeahdy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
|
||
int s = 0; | ||
int e = maxH; | ||
int ans = 0; | ||
while(s <= e) { | ||
KodaHye marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int mid = (s + e) / 2; | ||
|
||
long total = 0; | ||
for(int i=0; i<N; i++) { | ||
if(trr[i] > mid) total += (trr[i]-mid); | ||
} | ||
|
||
// 자른길이가 M보다 작다면 높이를 더 낮게 설정해서 자른길이의 합을 늘려야 함 | ||
if(total < M) { | ||
e = mid - 1; | ||
} else { | ||
ans = mid; | ||
s = mid + 1; | ||
} | ||
} | ||
|
||
System.out.println(ans); | ||
|
||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
BOJ/5001-10000번/JY_7579.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,54 @@ | ||
package day1016; | ||
|
||
import java.util.*; | ||
import java.io.*; | ||
|
||
public class JY_7579 { | ||
|
||
// 최대 비용(100개 * 100) | ||
static int MAX_COST = 10001; | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int N = Integer.parseInt(st.nextToken()); | ||
int M = Integer.parseInt(st.nextToken()); | ||
|
||
int[] mrr = new int[N+1]; | ||
st = new StringTokenizer(br.readLine()); | ||
for(int i=1; i<N+1; i++) { | ||
mrr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
int[] crr = new int[N+1]; | ||
st = new StringTokenizer(br.readLine()); | ||
for(int i=1; i<N+1; i++) { | ||
crr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
// dp[i][j] : i번쨰까지 확인했을때, j비용으로 비활성화할 수 있는 최대메모리 | ||
int[][] dp = new int[N+1][MAX_COST]; | ||
for(int i=1; i<N+1; i++) { | ||
// 비용은 0이될 수 있음 | ||
for(int j=0; j<MAX_COST; j++) { | ||
if(j < crr[i]) { | ||
dp[i][j] = dp[i-1][j]; | ||
} else { | ||
dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-crr[i]]+mrr[i]); | ||
} | ||
} | ||
} | ||
|
||
int ans = 0; | ||
// 적은 비용부터 탐색하며서 비활성화한 최대메모리가 M이상이면, 그때 비용이 최소비용 | ||
for(int j=0; j<MAX_COST; j++) { | ||
if(dp[N][j] >= M) { | ||
ans = j; | ||
break; | ||
} | ||
} | ||
|
||
System.out.println(ans); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
BOJ/5001-10000번/JY_9084.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,44 @@ | ||
package day1016; | ||
|
||
import java.util.*; | ||
import java.io.*; | ||
|
||
public class JY_9084 { | ||
|
||
static int MAX_COST = 10001; | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int T = Integer.parseInt(st.nextToken()); | ||
for(int t=0; t<T; t++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int N = Integer.parseInt(st.nextToken()); | ||
|
||
int[] coin = new int[N+1]; | ||
st = new StringTokenizer(br.readLine()); | ||
for(int i=1; i<N+1; i++) { | ||
coin[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
int M = Integer.parseInt(br.readLine()); | ||
|
||
int[] dp = new int[MAX_COST]; | ||
|
||
// 0원을 만드는 경우 : 1 | ||
dp[0] = 1; | ||
// dp[j] : j원을 만들 수 있는 경우의 수 | ||
// dp[j] : i-1번쨰 동전까지 확인했을 때 j를 만들 수 있는 경우의 수 + 새로운 i번쨰 동전으로 만들 수 있는 경우의수 | ||
for(int i=1; i<N+1; i++) { | ||
for(int j=coin[i]; j<M+1; j++) { | ||
dp[j] = dp[j] + dp[j-coin[i]]; | ||
} | ||
} | ||
|
||
System.out.println(dp[M]); | ||
} | ||
|
||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
CodeTree/2017-2018년/JY_테트리스_블럭_안의_합_최대화_하기.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,81 @@ | ||
package day1014; | ||
|
||
import java.util.*; | ||
import java.io.*; | ||
|
||
public class JY_테트리스_블럭_안의_합_최대화_하기 { | ||
|
||
static int N, M; | ||
static int[][] g; | ||
static boolean[][] visited; | ||
static int ans; | ||
// 현재 그래프 값 중 가장 큰 것 | ||
static int maxValue; | ||
static int[] dx = {0, 0, -1, 1}; | ||
static int[] dy = {-1, 1, 0, 0}; | ||
|
||
|
||
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()); | ||
|
||
g = new int[N][M]; | ||
maxValue = Integer.MIN_VALUE; | ||
for(int i=0; i<N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for(int j=0; j<M; j++) { | ||
g[i][j] = Integer.parseInt(st.nextToken()); | ||
maxValue = Math.max(maxValue, g[i][j]); | ||
} | ||
} | ||
|
||
visited = new boolean[N][M]; | ||
ans = Integer.MIN_VALUE; | ||
for(int i=0; i<N; i++) { | ||
for(int j=0; j<M; j++) { | ||
visited[i][j] = true; | ||
dfs(i, j, 1, g[i][j]); | ||
visited[i][j] = false; | ||
} | ||
} | ||
|
||
System.out.println(ans); | ||
|
||
} | ||
public static boolean inRange(int x, int y) { | ||
return x>=0 && x<N && y>=0 && y<M; | ||
} | ||
public static void dfs(int x, int y, int depth, int total) { | ||
// 4개의 블록 모두 탐색 | ||
if(depth == 4) { | ||
ans = Math.max(ans, total); | ||
return; | ||
} | ||
// 가지치기 | ||
// 현재까지 탐색한 결과에 앞으로 최댓값만 추가한다고 해도 ans값보다 작으면 탐색X | ||
if(ans >= total+maxValue*(4-depth)) return; | ||
|
||
for(int i=0; i<4; i++) { | ||
int nx = x + dx[i]; | ||
int ny = y + dy[i]; | ||
if(!inRange(nx, ny)) continue; | ||
if(visited[nx][ny]) continue; | ||
// 2번째 블럭인 경우, ᅡ ᅥ ᅩ ᅮ 처럼 2번째 블록에서 연결된 2개의 블록을 찾아야한다. | ||
if(depth == 2) { | ||
visited[nx][ny] = true; | ||
dfs(x, y, depth+1, total+g[nx][ny]); | ||
visited[nx][ny] = false; | ||
} | ||
|
||
// 2번쨰 블록 이외에는 일반탐색 | ||
visited[nx][ny] = true; | ||
dfs(nx, ny, depth+1, total+g[nx][ny]); | ||
visited[nx][ny] = false; | ||
|
||
} | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
Programmers/Level3/JY_42861.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,41 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
|
||
static int[] parents; | ||
|
||
public int solution(int n, int[][] costs) { | ||
int answer = 0; | ||
|
||
parents = new int[n]; | ||
for(int i=0; i<n; i++) { | ||
parents[i] = i; | ||
} | ||
|
||
// 비용 순으로 정렬 | ||
Arrays.sort(costs, (o1, o2)->(o1[2]-o2[2])); | ||
|
||
for(int[] cost: costs) { | ||
if(find(cost[0]) != find(cost[1])) { | ||
union(cost[0], cost[1]); | ||
answer += cost[2]; | ||
} | ||
} | ||
|
||
return answer; | ||
} | ||
public static int find(int x) { | ||
if(parents[x] != x) { | ||
parents[x] = find(parents[x]); | ||
} | ||
return parents[x]; | ||
} | ||
public static void union(int a, int b) { | ||
int pa = find(a); | ||
int pb = find(b); | ||
|
||
if(pa != pb) { | ||
parents[pb] = pa; | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
Programmers/Level3/JY_43238.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,41 @@ | ||
class Solution { | ||
public long solution(int n, int[] times) { | ||
long answer = 0; | ||
int T = times.length; | ||
|
||
// 가장 시간이 오래걸리는 심사관 | ||
long maxTime = 0; | ||
for(int i=0; i<T; i++){ | ||
maxTime = Math.max(maxTime, times[i]); | ||
} | ||
|
||
long s = 1; | ||
long e = maxTime*n; | ||
|
||
while(s <= e) { | ||
long mid = (s + e) / 2; | ||
// 현재 시간(mid)으로 심사할 수 있는 인원수 구하기 | ||
long pCnt = calPeople(n, mid, times); | ||
|
||
// n명보다 많다면 가능하고, 시간 더 줄일 수 있음 | ||
if(n <= pCnt) { | ||
answer = mid; | ||
e = mid - 1; | ||
} else{ | ||
s = mid + 1; | ||
} | ||
|
||
} | ||
|
||
return answer; | ||
} | ||
public static long calPeople(int n, long t, int[] times) { | ||
long total = 0; | ||
for(int i=0; i<times.length; i++) { | ||
// 한명당 심사할 수 있는 인원 수: 실행시간 / 심사시간 | ||
total += (t / times[i]); | ||
if(total > n) break; | ||
} | ||
return total; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
SQL/06주차/JY_대장균들의_자식의_수_구하기.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,9 @@ | ||
-- 대장균 자식의 수 구하기 | ||
-- https://school.programmers.co.kr/learn/courses/30/lessons/299305 | ||
|
||
SELECT P.ID, COUNT(C.ID) AS CHILD_COUNT | ||
FROM ECOLI_DATA P | ||
LEFT JOIN ECOLI_DATA C | ||
ON P.ID = C.PARENT_ID | ||
GROUP BY(P.ID) | ||
ORDER BY P.ID; |
8 changes: 8 additions & 0 deletions
SQL/06주차/JY_재구매가_일어난_상품과_회원_리스트_구하기.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,8 @@ | ||
-- 재구매가 일어난 상품과 회원 리스트 구하기 | ||
-- https://school.programmers.co.kr/learn/courses/30/lessons/131536 | ||
|
||
SELECT USER_ID, PRODUCT_ID | ||
FROM ONLINE_SALE | ||
GROUP BY USER_ID, PRODUCT_ID | ||
HAVING COUNT(USER_ID) >= 2 | ||
ORDER BY USER_ID, PRODUCT_ID DESC |
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.