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

Commit 1bb0d15

Browse files
authored
Merge pull request #328 from Jewan1120/main
[24주차] 백제완
2 parents 975541c + a0f47fd commit 1bb0d15

File tree

5 files changed

+181
-0
lines changed

5 files changed

+181
-0
lines changed

‎BOJ/1000-5000번/JW_2629.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
public class JW_2629 {
2+
3+
public static void main(String[] args) throws Exception {
4+
int n = read();
5+
int[] weights = new int[n + 1];
6+
for (int i = 1; i < n + 1; i++)
7+
weights[i] = read();
8+
int m = read(), maxTarget = 0;
9+
int[] targets = new int[m];
10+
for (int i = 0; i < m; i++) {
11+
targets[i] = read();
12+
maxTarget = Math.max(maxTarget, targets[i]);
13+
}
14+
// 가능한 범위까지 DP 배열 생성
15+
boolean[] dp = new boolean[maxTarget + 501];
16+
dp[0] = true;
17+
int w;
18+
for (int i = 1; i < n + 1; i++) {
19+
w = weights[i];
20+
boolean[] temp = dp.clone(); // 영향을 주지 않기 위해 새로운 배열 생성
21+
for (int j = dp.length - 1; j >= 0; j--) {
22+
if (dp[j]) {
23+
if (j + w < dp.length)
24+
temp[j + w] = true; // 더하기
25+
if (j - w >= 0)
26+
temp[j - w] = true; // 뺴기
27+
if (w - j >= 0)
28+
temp[w - j] = true; // 반대편에 놓기
29+
}
30+
}
31+
dp = temp;
32+
}
33+
StringBuilder sb = new StringBuilder();
34+
for (int i = 0; i < m; i++)
35+
sb.append(dp[targets[i]] ? 'Y' : 'N').append(' ');
36+
System.out.println(sb);
37+
}
38+
39+
private static int read() throws Exception {
40+
int c, n = System.in.read() & 15;
41+
while ((c = System.in.read()) >= 48)
42+
n = (n << 3) + (n << 1) + (c & 15);
43+
if (c == 13)
44+
System.in.read();
45+
return n;
46+
}
47+
}

‎BOJ/20001-25000번/JW_21578.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
public class JW_21578 {
2+
3+
public static void main(String[] args) throws Exception {
4+
int n = read();
5+
int[] arr = new int[n], lSum = new int[n], rSum = new int[n];
6+
for (int i = 0; i < n; i++)
7+
arr[i] = read();
8+
// 누적합 초기화
9+
lSum[0] = arr[0];
10+
rSum[n - 1] = arr[n - 1];
11+
for (int i = 1; i < n; i++) {
12+
lSum[i] = lSum[i - 1] + arr[i]; // 왼쪽에서 오른쪽으로 누적합
13+
rSum[n - 1 - i] = rSum[n - i] + arr[n - 1 - i]; // 오른쪽에서 왼쪽으로 누적합
14+
}
15+
int maxValue = 0;
16+
for (int i = 0; i < n; i++) {
17+
// 벌꿀벌
18+
maxValue = Math.max(maxValue, (lSum[i] + rSum[i] - lSum[0] - rSum[n - 1]));
19+
if (i > 0)
20+
// 벌벌꿀
21+
maxValue = Math.max(maxValue, (lSum[n - 1] - lSum[i]) * 2 + lSum[i - 1] - lSum[0]);
22+
if (i < n - 1)
23+
// 꿀벌벌
24+
maxValue = Math.max(maxValue, (rSum[0] - rSum[i]) * 2 + rSum[i + 1] - rSum[n - 1]);
25+
}
26+
System.out.println(maxValue);
27+
}
28+
29+
private static int read() throws Exception {
30+
int c, n = System.in.read() & 15;
31+
while ((c = System.in.read()) >= 48)
32+
n = (n << 3) + (n << 1) + (c & 15);
33+
if (c == 13)
34+
System.in.read();
35+
return n;
36+
}
37+
}

‎BOJ/30000-35000번/JW_30407.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.util.ArrayDeque;
2+
import java.util.Deque;
3+
4+
public class JW_30407 {
5+
6+
public static void main(String[] args) throws Exception {
7+
int n = read();
8+
Deque<int[]> dq = new ArrayDeque<>();
9+
int h = read(), d = read(), k = read();
10+
dq.offer(new int[] { h, d, 1, 0 });
11+
int t = 0, damage = 0, tempDamage = 0;
12+
while (n-- > 0) {
13+
t = dq.size();
14+
tempDamage = read();
15+
while (t-- > 0) {
16+
int[] cur = dq.poll();
17+
damage = Math.max(0, tempDamage - cur[1]); // 받을 데미지
18+
// 현재 체력이 0 이하라면 건너뛰기
19+
if (cur[0] <= 0)
20+
continue;
21+
// 깜짝 놀래켰었다면
22+
if (cur[3] == 1) {
23+
cur[3] = 0;
24+
damage = 0;
25+
}
26+
// 깜짝 놀래킬 수 있다면
27+
if (cur[2] != 0)
28+
dq.offer(new int[] { cur[0] - damage, cur[1], 0, 1 });
29+
dq.offer(new int[] { cur[0] - Math.max(0, damage - k), cur[1] + k, cur[2], cur[3] });
30+
dq.offer(new int[] { cur[0] - damage / 2, cur[1], cur[2], cur[3] });
31+
}
32+
}
33+
// 최댓값 갱신
34+
int maxH = 0;
35+
while (!dq.isEmpty()) {
36+
int[] cur = dq.poll();
37+
if (cur[0] <= 0)
38+
continue;
39+
maxH = Math.max(maxH, cur[0]);
40+
}
41+
System.out.println(maxH != 0 ? maxH : -1);
42+
}
43+
44+
private static int read() throws Exception {
45+
int c, n = System.in.read() & 15;
46+
while ((c = System.in.read()) >= 48)
47+
n = (n << 3) + (n << 1) + (c & 15);
48+
if (c == 13)
49+
System.in.read();
50+
return n;
51+
}
52+
}

‎Programmers/Level2/JW_148652.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public int solution(int n, long l, long r) {
3+
return recursive(1, (long) Math.pow(5, n), l, r);
4+
}
5+
6+
private int recursive(long s, long e, long l, long r) {
7+
// 유효하지 않은 범위라면 종료
8+
if (e <= l || r < s)
9+
return 0;
10+
// 최대까지 내려왔다면 1반환
11+
if (e - s == 1)
12+
return 1;
13+
long size = (e - s + 1) / 5;
14+
int count = 0;
15+
// 다음 칸토어 재귀
16+
for (int i = 0; i < 5; i++) {
17+
// 0인 부분은 제외
18+
if (i == 2)
19+
continue;
20+
count += recursive(s + i * size, s + (i + 1) * size, l, r);
21+
}
22+
return count;
23+
}
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
WITH TOTAL AS (
2+
SELECT
3+
*
4+
FROM
5+
JULY
6+
UNION ALL
7+
SELECT
8+
*
9+
FROM
10+
FIRST_HALF
11+
)
12+
13+
SELECT
14+
FLAVOR
15+
FROM
16+
TOTAL
17+
GROUP BY
18+
FLAVOR
19+
ORDER BY
20+
SUM(TOTAL_ORDER) DESC
21+
LIMIT 3

0 commit comments

Comments
(0)

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