-
Notifications
You must be signed in to change notification settings - Fork 4
[6주차] 배수빈 #78
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
[6주차] 배수빈 #78
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4115699
배수빈: [CT] 테트리스 블럭 안의 합 최대화 하기_241014
baexxbin 8c8970a
배수빈: [BOJ] 2805 나무자르기_241015
baexxbin 600b520
배수빈: [BOJ] 2110 공유기 설치_241015
baexxbin 84c303c
배수빈: [SQL] Managers with at Least 5 Direct Reports_241015
baexxbin c68ef15
배수빈: [BOJ] 7579 앱_241016
baexxbin 189bd52
배수빈: [BOJ] 9084 동전_241016
baexxbin d9d15db
배수빈: [PG] 43238 이분탐색_241017
baexxbin 2ec9b10
배수빈: [SQL] Count Salary Categories_241017
baexxbin 6d17422
배수빈: [PG] 42861 섬 연결하기_241018
baexxbin 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
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,49 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_2110 { | ||
static int N, C; | ||
static int[] house; | ||
|
||
private static boolean canWifi(int dist) { | ||
int cnt = 1; | ||
int pre = house[0]; | ||
for (int i = 1; i < N; i++) { | ||
if (house[i]-pre >= dist){ | ||
cnt++; | ||
pre = house[i]; | ||
} | ||
if (cnt >=C) return true; | ||
} | ||
return false; | ||
} | ||
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()); | ||
|
||
house = new int[N]; | ||
for (int i = 0; i < N; i++) { | ||
house[i] = Integer.parseInt(br.readLine()); | ||
} | ||
Arrays.sort(house); | ||
|
||
// 거리: mid, 공유기 개수: C (조건) | ||
int s = 1; | ||
int e = house[N-1] - house[0]; | ||
int parm = 0; | ||
while (s <= e) { | ||
int mid = (s + e) / 2; | ||
if (canWifi(mid)) { // 공유기 가능하면 거리 더 늘려보기 | ||
parm = mid; | ||
s = mid+1; | ||
}else e = mid-1; | ||
} | ||
System.out.println(parm); | ||
} | ||
} |
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,62 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_2805 { | ||
static int N, M; | ||
static int[] trees; | ||
|
||
// 파라미터 서치: 잘린 길이가 M보다 크거나 같은가 | ||
// 높이 최대값: mid변수 | ||
private static boolean canGet(int idx, int h) { | ||
long cnt = 0; | ||
for (int i = idx; i < N; i++) { | ||
cnt += trees[i]-h; | ||
if (cnt>=M) return true; | ||
} | ||
return cnt>=M; | ||
} | ||
|
||
private static int findIdx(int h) { // 얘도 upper-bound로 인덱스 위치 찾기 | ||
int left = 0; | ||
int right = N; // upper-bound시 탐색범위는 [0,N) | ||
while (left < right){ | ||
int mid = (left+right)/2; | ||
if (trees[mid] <= h) left = mid+1; | ||
else right = mid; | ||
} | ||
return left; | ||
} | ||
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()); | ||
|
||
trees = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
trees[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
Arrays.sort(trees); | ||
|
||
int left = 0; // 절단기 높이값이 작을 수록 많이 자름 | ||
int right = trees[N-1]; | ||
int parm = 0; | ||
|
||
while (left <= right){ // 절단기 높이의 최대값이므로 upper-bound | ||
int height = (left+right)/2; | ||
int idx = findIdx(height); | ||
if (canGet(idx, height)) { | ||
parm = height; | ||
left = height+1; // 나무 얻을 수 있으면 높이 조금 더 높여보기 | ||
} | ||
else right = height-1; | ||
} | ||
System.out.println(parm); | ||
} | ||
} |
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,50 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_7579 { | ||
static int N, M; | ||
static int[] memo, cost; | ||
|
||
|
||
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()); | ||
|
||
memo = new int[N]; | ||
cost = new int[N]; | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
memo[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
cost[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
// 비활성화 비용 최소화로 M바이트 확보 | ||
int[] dp = new int[10001]; | ||
|
||
// dp[i] = j : i비용으로 얻을 수 있는 최대 메모리 j | ||
for (int i = 0; i <N; i++) { // 앱 번호 | ||
for (int j = 10000; j >=cost[i]; j--) { // 비용 | ||
dp[j] = Math.max(dp[j], dp[j - cost[i]] + memo[i]); | ||
} | ||
} | ||
|
||
int ans = 0; | ||
for (int i = 0; i <= 10000; i++) { | ||
if (dp[i] >=M) { | ||
ans = i; | ||
break; | ||
} | ||
} | ||
System.out.println(ans); | ||
} | ||
} |
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,38 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_9084 { | ||
private static int calMethod(int N, int[] coin, int M) { | ||
int[] dp = new int[M + 1]; | ||
dp[0] = 1; | ||
|
||
for (int c : coin) { | ||
for (int i = c; i <= M; i++) { | ||
dp[i] += dp[i - c]; | ||
} | ||
} | ||
return dp[M]; | ||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
int T = Integer.parseInt(br.readLine()); | ||
|
||
while (T-- > 0) { | ||
int N = Integer.parseInt(br.readLine()); | ||
int[] coin = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
coin[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
int M = Integer.parseInt(br.readLine()); | ||
|
||
sb.append(calMethod(N, coin, M)).append('\n'); | ||
} | ||
System.out.println(sb); | ||
} | ||
} |
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,62 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class SB_테트리스_블럭_안의_합_최대화_하기 { | ||
static int N,M; | ||
static int[][] board; | ||
static boolean[][] visited; | ||
static int mx = 0; | ||
static int[] dx = {-1, 1, 0, 0}; | ||
static int[] dy = {0, 0, -1, 1}; | ||
|
||
private static void dfs(int x, int y, int depth, int total) { | ||
// if (mx > mx*(4-depth)+total) return; | ||
if(depth==4){ | ||
mx = Math.max(mx, total); | ||
return; | ||
} | ||
|
||
for (int i = 0; i < 4; i++) { | ||
int nx = x+dx[i]; | ||
int ny = y+dy[i]; | ||
if (!isValid(nx, ny) || visited[nx][ny]) continue; | ||
if (depth == 2) { | ||
visited[nx][ny] = true; | ||
dfs(x, y, depth+1, total+board[nx][ny]); // ㅜ 가 갈라지는 중점에서 양옆 탐색 | ||
visited[nx][ny] = false; | ||
} | ||
visited[nx][ny] = true; | ||
dfs(nx, ny, depth+1, total+board[nx][ny]); | ||
visited[nx][ny] = false; | ||
} | ||
} | ||
|
||
private static boolean isValid(int x, int y) { | ||
return 0<=x && x<N && 0<=y && y<M; | ||
} | ||
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()); | ||
|
||
board = new int[N][M]; | ||
visited = new boolean[N][M]; | ||
for(int i=0; i<N; i++){ | ||
st = new StringTokenizer(br.readLine()); | ||
for (int j = 0; j < M; j++) { | ||
board[i][j] = Integer.parseInt(st.nextToken()); | ||
} | ||
} | ||
|
||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < M; j++) { | ||
visited[i][j] = true; | ||
dfs(i, j, 1, board[i][j]); | ||
visited[i][j] = false; | ||
} | ||
} | ||
System.out.println(mx); | ||
} | ||
} |
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,42 @@ | ||
import java.util.Arrays; | ||
|
||
class Solution { | ||
static int[] parents; | ||
|
||
private static int find(int x) { | ||
if (parents[x] != x) { | ||
return find(parents[x]); | ||
} | ||
return parents[x]; | ||
} | ||
|
||
private static void union(int a, int b) { | ||
if (a > b) parents[b] = a; | ||
else parents[a] = b; | ||
} | ||
public static int solution(int n, int[][] costs) { | ||
Arrays.sort(costs, (o1, o2)->{ | ||
return o1[2]-o2[2]; | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 따로 Queue를 사용하지 않고 배열을 정렬해서 풀이하신 것 좋습니다,,,,👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 히히 감사합니돠아😊 |
||
|
||
parents = new int[n]; | ||
for (int i = 0; i < n; i++) { | ||
parents[i] = i; | ||
} | ||
|
||
int cnt = 1; | ||
int ans = 0; | ||
for (int[] cur : costs) { | ||
if (cnt==n) break; | ||
int p_a = find(cur[0]); | ||
int p_b = find(cur[1]); | ||
|
||
if (p_a != p_b) { | ||
union(p_a, p_b); | ||
ans+=cur[2]; | ||
cnt++; | ||
} | ||
} | ||
return ans; | ||
} | ||
} |
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,31 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
private static boolean canCheck(long target, int[] times, int n) { | ||
long cnt = 0; | ||
for (int tm : times) { | ||
cnt += target / tm; | ||
if (cnt >= n) return true; | ||
} | ||
return false; | ||
} | ||
public static long solution(int n, int[] times) { | ||
Arrays.sort(times); | ||
|
||
// 매개변수 탐색, 주어진 시간 내 n명 이상의 사람 처리할 수 있는지 | ||
long left = 0; | ||
long right = (long) times[times.length - 1] * n; // 최대 시간 | ||
|
||
long parm = 0; | ||
while (left <= right) { | ||
long mid = (left + right) / 2; | ||
if (canCheck(mid, times, n)) { | ||
parm = mid; | ||
right = mid - 1; | ||
} else { | ||
left = mid + 1; | ||
} | ||
} | ||
return parm; | ||
} | ||
} |
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,14 @@ | ||
# 각 급여 범주에 대한 은행 계좌 수를 계산 | ||
# 결과표에는 세 가지 범주가 모두 포함되어야 합니다. 카테고리에 계정이 없으면 0 반환 | ||
|
||
SELECT 'High Salary' AS category, | ||
SUM(income > 50000) AS accounts_count | ||
FROM Accounts | ||
UNION | ||
SELECT 'Average Salary' AS category, | ||
SUM(income BETWEEN 20000 AND 50000) AS accounts_count | ||
FROM Accounts | ||
UNION | ||
SELECT 'Low Salary' AS category, | ||
SUM(income < 20000) AS accounts_count | ||
FROM Accounts |
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,7 @@ | ||
# 최소 5명의 직속 부하 직원이 있는 관리자를 찾기 | ||
|
||
SELECT e.name | ||
FROM Employee e | ||
JOIN Employee m ON e.id = m.managerId | ||
GROUP BY m.managerId | ||
HAVING COUNT(m.managerId) >=5; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는
i
시작을0
으로 설정해줘서, 범위에 벗어나면continue
를 해주었는데i
시작을 처음부터c
로 시작해주면 되군요!!