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 b2b22f1

Browse files
authored
Merge pull request #327 from GreatAlgorithm-Study/xubin
[24주차] 배수빈
2 parents 1bb0d15 + 365769e commit b2b22f1

File tree

6 files changed

+304
-0
lines changed

6 files changed

+304
-0
lines changed

‎BOJ/1000-5000번/SB_2629.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class SB_2629 {
7+
static int N;
8+
static int[] weight;
9+
static boolean[][] dp;
10+
11+
private static void recursive(int idx, int w) {
12+
if (idx > N || dp[idx][w]) return;
13+
dp[idx][w] = true;
14+
recursive(idx + 1, w + weight[idx]); // 새로운 추를 기존 무게와 더할 경우
15+
recursive(idx + 1, Math.abs(w - weight[idx])); // 새로운 추를 기존 무게와 뺄 경우
16+
recursive(idx + 1, w); // 새로운 추를 선택하지 않을 경우
17+
}
18+
public static void main(String[] args) throws IOException {
19+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
20+
StringTokenizer st;
21+
StringBuilder sb = new StringBuilder();
22+
23+
N = Integer.parseInt(br.readLine());
24+
int mx = N * 500; // 주어진 구슬로 확인 가능한 최대 무게
25+
weight = new int[N+1];
26+
dp = new boolean[N + 1][(N * 500) + 1];
27+
28+
st = new StringTokenizer(br.readLine());
29+
for (int i = 0; i < N; i++) {
30+
weight[i] = Integer.parseInt(st.nextToken());
31+
}
32+
33+
recursive(0, 0);
34+
35+
int M = Integer.parseInt(br.readLine());
36+
st = new StringTokenizer(br.readLine());
37+
for (int i = 0; i < M; i++) {
38+
int mv = Integer.parseInt(st.nextToken());
39+
if (mv > mx || !dp[N][mv]) sb.append("N").append(" ");
40+
else sb.append("Y").append(" ");
41+
}
42+
System.out.println(sb);
43+
}
44+
}

‎BOJ/20001-25000번/SB_21758.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.Arrays;
5+
import java.util.StringTokenizer;
6+
7+
public class boj_21758 {
8+
static int N;
9+
static int[] arr;
10+
static int[] sum;
11+
public static void main(String[] args) throws IOException {
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
StringTokenizer st;
14+
15+
N = Integer.parseInt(br.readLine());
16+
arr = new int[N];
17+
sum = new int[N];
18+
19+
st = new StringTokenizer(br.readLine());
20+
for (int i = 0; i < N; i++) {
21+
arr[i] = Integer.parseInt(st.nextToken());
22+
if (i==0) sum[i] = arr[i];
23+
else sum[i] += arr[i]+sum[i-1];
24+
}
25+
26+
int ans = 0;
27+
for (int i = 1; i < N - 1; i++) {
28+
ans = Math.max(ans, (sum[N - 1] - arr[0] - arr[i]) + (sum[N - 1] - sum[i])); // 벌 벌 꿀
29+
ans = Math.max(ans, sum[i - 1] + (sum[N - 2] - arr[i])); // 꿀 벌 벌
30+
ans = Math.max(ans, (sum[i] - arr[0]) + (sum[N - 2] - sum[i - 1])); // 벌 꿀 벌
31+
}
32+
System.out.println(ans);
33+
}
34+
}

‎BOJ/30000-35000번/SB_30407.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class SB_30407 {
7+
static int N, H, D, K;
8+
static int[] attack;
9+
static int ans = 0;
10+
11+
private static void dfs(int depth, int hp, int d, int atk, boolean isUse) {
12+
if (depth == N) {
13+
ans = Math.max(ans, hp);
14+
return;
15+
}
16+
if (hp <= ans || hp <= 0) return;
17+
18+
int wounk = Math.max(0, atk - d);
19+
dfs(depth + 1, hp - (wounk / 2), d, attack[depth + 1], isUse);
20+
21+
int run = Math.max(0, atk - (d + K));
22+
dfs(depth + 1, hp - run, d + K, attack[depth + 1], isUse);
23+
24+
if (!isUse) {
25+
int fright = Math.max(0, atk - d);
26+
dfs(depth + 1, hp - fright, d, 0, true);
27+
}
28+
}
29+
30+
public static void main(String[] args) throws IOException {
31+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
32+
StringTokenizer st;
33+
34+
N = Integer.parseInt(br.readLine());
35+
st = new StringTokenizer(br.readLine());
36+
H = Integer.parseInt(st.nextToken()); // 체력
37+
D = Integer.parseInt(st.nextToken()); // 거리
38+
K = Integer.parseInt(st.nextToken()); // 이동 거리
39+
40+
attack = new int[N + 1];
41+
for (int i = 0; i < N; i++) {
42+
attack[i] = Integer.parseInt(br.readLine());
43+
}
44+
45+
dfs(0, H, D, attack[0], false);
46+
System.out.println(ans <= 0 ? -1 : ans);
47+
}
48+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.*;
5+
6+
public class SB_코드트리오마카세 {
7+
static int L;
8+
static HashMap<String, List<Sushi>> waitSushi = new HashMap<>(); // 사람 별 먹을 초밥 관리 대기열
9+
static HashMap<String, Enter> guestInfo = new HashMap<>(); // 손님의 입장 정보 관리
10+
static int INF = Integer.MAX_VALUE;
11+
static PriorityQueue<Node> pq = new PriorityQueue<>(); // 바로 먹을 초밥 관리
12+
static int totalSushi = 0;
13+
static int totalGuest = 0;
14+
static StringBuilder sb = new StringBuilder();
15+
private static int getEatTime(Enter enter, Sushi sushi) { // 손님의 입장 정보와 스시 생성 정보로 먹히는 시간 구하기
16+
int wait;
17+
if (enter.tm < sushi.tm) { // 손님이 스시보다 빨리옴
18+
if (enter.pos < sushi.pos) wait = L - sushi.pos + enter.pos; // (초밥이 손님보다 앞에 있음)초밥이 한바퀴 돌아서 손님한테 도착
19+
else wait = enter.pos - sushi.pos; // (초밥이 손님 뒤에 있음) 손님까지 거리만 이동하면 도착
20+
return sushi.tm + wait; // 스시가 만들어져서 손님한테 전달되는 시간
21+
} else { // 스시가 손님보다 먼저 만들어짐
22+
int afterRotatePos = (sushi.pos + (enter.tm - sushi.tm)) % L; // 손님이 도착할때까지 회전했을때 위치
23+
if (enter.pos < afterRotatePos) wait = L - afterRotatePos + enter.pos;
24+
else wait = enter.pos - afterRotatePos;
25+
return enter.tm + wait;
26+
}
27+
}
28+
29+
private static void makeSushi(int t, int x, String name) { // 초밥 만들기
30+
Sushi sushi = new Sushi(t, x, name, INF);
31+
if (!guestInfo.containsKey(name) || !guestInfo.get(name).isEnter) { // 사람 안왔는데 스시 미리 만듦
32+
waitSushi.computeIfAbsent(name, k -> new ArrayList<>()).add(sushi); // 스시 대기열에서 대기
33+
} else { // 사람이 온 후에 스시가 만들어짐
34+
int eatTime = getEatTime(guestInfo.get(name), sushi); // 회전해서 스시를 먹는 시간 구하기
35+
pq.offer(new Node(eatTime, name)); // 바로먹을 큐에 삽입
36+
}
37+
totalSushi++;
38+
}
39+
40+
private static void enterGuest(int t, int x, String name, int n) { // 손님 입장
41+
guestInfo.put(name, new Enter(t, x, n));
42+
totalGuest++;
43+
44+
if (waitSushi.containsKey(name) && !waitSushi.get(name).isEmpty()) { // 해당 손님의 스시가 있을 경우 스시 먹기
45+
for (Sushi sushi : waitSushi.get(name)) {
46+
int eatTime = getEatTime(guestInfo.get(name), sushi);
47+
pq.offer(new Node(eatTime, name)); // 바로 먹힐 초밥 관리하는 큐에 정보 저장
48+
}
49+
waitSushi.get(name).clear();
50+
}
51+
}
52+
53+
private static void takePhoto(int t) { // 사진 찍기 겸 진짜 초밥 먹기
54+
while (!pq.isEmpty()) {
55+
Node node = pq.peek();
56+
if (node.eatTm > t) break; // 현재 시간보다 늦게 먹히는 초밥이면 그만
57+
pq.poll();
58+
totalSushi--;
59+
guestInfo.get(node.guestName).cnt--; // 먹은 초밥수--
60+
if (guestInfo.get(node.guestName).cnt==0) totalGuest--; // 초밥 다 먹으면 나가기
61+
}
62+
sb.append(totalGuest).append(" ").append(totalSushi).append("\n"); // 사진 찍기
63+
}
64+
public static void main(String[] args) throws IOException {
65+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
66+
StringTokenizer st = new StringTokenizer(br.readLine());
67+
68+
L = Integer.parseInt(st.nextToken());
69+
int Q = Integer.parseInt(st.nextToken());
70+
71+
while (Q-- > 0) {
72+
st = new StringTokenizer(br.readLine());
73+
int cmd = Integer.parseInt(st.nextToken());
74+
if (cmd == 100) {
75+
int t = Integer.parseInt(st.nextToken());
76+
int x = Integer.parseInt(st.nextToken());
77+
String name = st.nextToken();
78+
makeSushi(t, x, name);
79+
} else if (cmd == 200) {
80+
int t = Integer.parseInt(st.nextToken());
81+
int x = Integer.parseInt(st.nextToken());
82+
String name = st.nextToken();
83+
int n = Integer.parseInt(st.nextToken());
84+
enterGuest(t, x, name, n);
85+
} else {
86+
int t = Integer.parseInt(st.nextToken());
87+
takePhoto(t);
88+
}
89+
}
90+
System.out.println(sb);
91+
}
92+
93+
static class Sushi{
94+
int tm, pos, et; // 시간, 초밥 위치, 먹은 시간
95+
String owner; // 초밥 주인
96+
97+
public Sushi(int tm, int pos, String owner, int et) {
98+
this.tm = tm;
99+
this.pos = pos;
100+
this.owner = owner;
101+
this.et = et;
102+
}
103+
}
104+
105+
static class Enter{
106+
int tm, pos, cnt; // 시간, 위치, 먹은 개수
107+
boolean isEnter = true; // 입장여부
108+
109+
public Enter(int tm, int pos, int cnt) {
110+
this.tm = tm;
111+
this.pos = pos;
112+
this.cnt = cnt;
113+
}
114+
}
115+
116+
static class Node implements Comparable<Node>{
117+
int eatTm;
118+
String guestName;
119+
120+
public Node(int eatTm, String guestName) {
121+
this.eatTm = eatTm;
122+
this.guestName = guestName;
123+
}
124+
125+
@Override
126+
public int compareTo(Node o) {
127+
return this.eatTm - o.eatTm;
128+
}
129+
}
130+
}

‎Programmers/Level2/SB_148652.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class SB_148652 {
2+
private static boolean isOne(long num) {
3+
while (num > 0) {
4+
if (num % 5 == 2) return false;
5+
num /= 5;
6+
}
7+
return true;
8+
}
9+
public static int solution(int n, long l, long r) {
10+
l --;
11+
12+
int ans = 0;
13+
for (long i = l; i < r; i++) {
14+
if (isOne(i)) ans++;
15+
}
16+
return ans;
17+
}
18+
19+
public static void main(String[] args) {
20+
int n = 2;
21+
long l = 4;
22+
long r = 17;
23+
System.out.println(solution(n, l, r));
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- 자동차 종류가 '세단' 또는 'SUV' 인 자동차 중
2+
-- 2022년 11월 1일부터 2022년 11월 30일까지 대여 가능하고
3+
-- 30일간의 대여 금액이 50만원 이상 200만원 미만인 자동차에 대해서
4+
-- 자동차 ID, 자동차 종류, 대여 금액(컬럼명: FEE) 리스트를 출력하는 SQL문을 작성
5+
-- 결과는 대여 금액을 기준으로 내림차순 정렬하고, 대여 금액이 같은 경우 자동차 종류를 기준으로 오름차순 정렬, 자동차 종류까지 같은 경우 자동차 ID를 기준으로 내림차순 정렬
6+
7+
SELECT A.CAR_ID, A.CAR_TYPE,
8+
ROUND(A.DAILY_FEE*((100-C.DISCOUNT_RATE)/100)*30) AS FEE
9+
FROM CAR_RENTAL_COMPANY_CAR A
10+
JOIN CAR_RENTAL_COMPANY_RENTAL_HISTORY B
11+
ON A.CAR_ID = B.CAR_ID
12+
JOIN CAR_RENTAL_COMPANY_DISCOUNT_PLAN C
13+
ON A.CAR_TYPE = C.CAR_TYPE
14+
WHERE A.CAR_TYPE IN ('세단', 'SUV')
15+
AND A.CAR_ID NOT IN (
16+
SELECT CAR_ID
17+
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
18+
WHERE END_DATE > '2022年11月01日' AND START_DATE < '2022年12月01日'
19+
)
20+
AND C.DURATION_TYPE = '30일 이상'
21+
GROUP BY A.CAR_ID
22+
HAVING FEE >= 500000 AND FEE < 2000000
23+
ORDER BY FEE DESC, A.CAR_TYPE ASC, CAR_ID DESC

0 commit comments

Comments
(0)

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