-
Notifications
You must be signed in to change notification settings - Fork 4
[24주차] 백제완 #328
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
[24주차] 백제완 #328
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f13c12
백제완: [BOJ] 21578 꿀 따기_250225
jewan100 9fc8660
백제완: [BOJ] 30407 나비의 간식을 훔쳐먹은 춘배_250226
jewan100 367e982
백제완: [PG] 148652 유사 칸토어 비트열_250227
jewan100 6bc30ba
백제완: [BOJ] 2629 양팔저울_250228
jewan100 a0f47fd
백제완: [SQL] 주문량이 많은 아이스크림들 조회하기_250226
jewan100 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
47 changes: 47 additions & 0 deletions
BOJ/1000-5000번/JW_2629.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,47 @@ | ||
public class JW_2629 { | ||
|
||
public static void main(String[] args) throws Exception { | ||
int n = read(); | ||
int[] weights = new int[n + 1]; | ||
for (int i = 1; i < n + 1; i++) | ||
weights[i] = read(); | ||
int m = read(), maxTarget = 0; | ||
int[] targets = new int[m]; | ||
for (int i = 0; i < m; i++) { | ||
targets[i] = read(); | ||
maxTarget = Math.max(maxTarget, targets[i]); | ||
} | ||
// 가능한 범위까지 DP 배열 생성 | ||
boolean[] dp = new boolean[maxTarget + 501]; | ||
dp[0] = true; | ||
int w; | ||
for (int i = 1; i < n + 1; i++) { | ||
w = weights[i]; | ||
boolean[] temp = dp.clone(); // 영향을 주지 않기 위해 새로운 배열 생성 | ||
for (int j = dp.length - 1; j >= 0; j--) { | ||
if (dp[j]) { | ||
if (j + w < dp.length) | ||
temp[j + w] = true; // 더하기 | ||
if (j - w >= 0) | ||
temp[j - w] = true; // 뺴기 | ||
if (w - j >= 0) | ||
temp[w - j] = true; // 반대편에 놓기 | ||
} | ||
} | ||
dp = temp; | ||
} | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < m; i++) | ||
sb.append(dp[targets[i]] ? 'Y' : 'N').append(' '); | ||
System.out.println(sb); | ||
} | ||
|
||
private static int read() throws Exception { | ||
int c, n = System.in.read() & 15; | ||
while ((c = System.in.read()) >= 48) | ||
n = (n << 3) + (n << 1) + (c & 15); | ||
if (c == 13) | ||
System.in.read(); | ||
return n; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
BOJ/20001-25000번/JW_21578.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,37 @@ | ||
public class JW_21578 { | ||
|
||
public static void main(String[] args) throws Exception { | ||
int n = read(); | ||
int[] arr = new int[n], lSum = new int[n], rSum = new int[n]; | ||
for (int i = 0; i < n; i++) | ||
arr[i] = read(); | ||
// 누적합 초기화 | ||
lSum[0] = arr[0]; | ||
rSum[n - 1] = arr[n - 1]; | ||
for (int i = 1; i < n; i++) { | ||
lSum[i] = lSum[i - 1] + arr[i]; // 왼쪽에서 오른쪽으로 누적합 | ||
rSum[n - 1 - i] = rSum[n - i] + arr[n - 1 - i]; // 오른쪽에서 왼쪽으로 누적합 | ||
} | ||
int maxValue = 0; | ||
for (int i = 0; i < n; i++) { | ||
// 벌꿀벌 | ||
maxValue = Math.max(maxValue, (lSum[i] + rSum[i] - lSum[0] - rSum[n - 1])); | ||
if (i > 0) | ||
// 벌벌꿀 | ||
maxValue = Math.max(maxValue, (lSum[n - 1] - lSum[i]) * 2 + lSum[i - 1] - lSum[0]); | ||
if (i < n - 1) | ||
// 꿀벌벌 | ||
maxValue = Math.max(maxValue, (rSum[0] - rSum[i]) * 2 + rSum[i + 1] - rSum[n - 1]); | ||
} | ||
System.out.println(maxValue); | ||
} | ||
|
||
private static int read() throws Exception { | ||
int c, n = System.in.read() & 15; | ||
while ((c = System.in.read()) >= 48) | ||
n = (n << 3) + (n << 1) + (c & 15); | ||
if (c == 13) | ||
System.in.read(); | ||
return n; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
BOJ/30000-35000번/JW_30407.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,52 @@ | ||
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
|
||
public class JW_30407 { | ||
|
||
public static void main(String[] args) throws Exception { | ||
int n = read(); | ||
Deque<int[]> dq = new ArrayDeque<>(); | ||
int h = read(), d = read(), k = read(); | ||
dq.offer(new int[] { h, d, 1, 0 }); | ||
int t = 0, damage = 0, tempDamage = 0; | ||
while (n-- > 0) { | ||
t = dq.size(); | ||
tempDamage = read(); | ||
while (t-- > 0) { | ||
int[] cur = dq.poll(); | ||
damage = Math.max(0, tempDamage - cur[1]); // 받을 데미지 | ||
// 현재 체력이 0 이하라면 건너뛰기 | ||
if (cur[0] <= 0) | ||
continue; | ||
// 깜짝 놀래켰었다면 | ||
if (cur[3] == 1) { | ||
cur[3] = 0; | ||
damage = 0; | ||
} | ||
// 깜짝 놀래킬 수 있다면 | ||
if (cur[2] != 0) | ||
dq.offer(new int[] { cur[0] - damage, cur[1], 0, 1 }); | ||
dq.offer(new int[] { cur[0] - Math.max(0, damage - k), cur[1] + k, cur[2], cur[3] }); | ||
dq.offer(new int[] { cur[0] - damage / 2, cur[1], cur[2], cur[3] }); | ||
} | ||
} | ||
// 최댓값 갱신 | ||
int maxH = 0; | ||
while (!dq.isEmpty()) { | ||
int[] cur = dq.poll(); | ||
if (cur[0] <= 0) | ||
continue; | ||
maxH = Math.max(maxH, cur[0]); | ||
} | ||
System.out.println(maxH != 0 ? maxH : -1); | ||
} | ||
|
||
private static int read() throws Exception { | ||
int c, n = System.in.read() & 15; | ||
while ((c = System.in.read()) >= 48) | ||
n = (n << 3) + (n << 1) + (c & 15); | ||
if (c == 13) | ||
System.in.read(); | ||
return n; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
Programmers/Level2/JW_148652.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,24 @@ | ||
class Solution { | ||
public int solution(int n, long l, long r) { | ||
return recursive(1, (long) Math.pow(5, n), l, r); | ||
} | ||
|
||
private int recursive(long s, long e, long l, long r) { | ||
// 유효하지 않은 범위라면 종료 | ||
if (e <= l || r < s) | ||
return 0; | ||
// 최대까지 내려왔다면 1반환 | ||
if (e - s == 1) | ||
return 1; | ||
long size = (e - s + 1) / 5; | ||
int count = 0; | ||
// 다음 칸토어 재귀 | ||
for (int i = 0; i < 5; i++) { | ||
// 0인 부분은 제외 | ||
if (i == 2) | ||
continue; | ||
count += recursive(s + i * size, s + (i + 1) * size, l, r); | ||
} | ||
return count; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
SQL/24주차/주문량이_많은_아이스크림들_조회하기.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,21 @@ | ||
WITH TOTAL AS ( | ||
SELECT | ||
* | ||
FROM | ||
JULY | ||
UNION ALL | ||
SELECT | ||
* | ||
FROM | ||
FIRST_HALF | ||
) | ||
|
||
SELECT | ||
FLAVOR | ||
FROM | ||
TOTAL | ||
GROUP BY | ||
FLAVOR | ||
ORDER BY | ||
SUM(TOTAL_ORDER) DESC | ||
LIMIT 3 |
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.