Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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
KodaHye merged 5 commits into GreatAlgorithm-Study:main from jewan100:main
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions BOJ/1000-5000번/JW_2629.java
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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;
}
}
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /