-
Notifications
You must be signed in to change notification settings - Fork 4
[24주차] 배수빈 #327
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
[24주차] 배수빈 #327
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e07d53
배수빈: [BOJ] 21758 꿀 따기_250226
baexxbin 9a3cd49
배수빈: [PG] 148652 유사칸토어 비트열_250227
baexxbin 4e12bd4
배수빈: [SQL] 특정 기간동안 대여 가능한 자동차들의 대여비용 구하기_250227
baexxbin d9a14f4
배수빈: [BOJ] 2629 양팔저울_250228
baexxbin daf40c7
배수빈: [BOJ] 30407 나비의 간식을 훔쳐먹은 춘배_250228
baexxbin 365769e
배수빈: [CT] 코드트리 오마카세_250302
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
44 changes: 44 additions & 0 deletions
BOJ/1000-5000번/SB_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,44 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_2629 { | ||
static int N; | ||
static int[] weight; | ||
static boolean[][] dp; | ||
|
||
private static void recursive(int idx, int w) { | ||
if (idx > N || dp[idx][w]) return; | ||
dp[idx][w] = true; | ||
recursive(idx + 1, w + weight[idx]); // 새로운 추를 기존 무게와 더할 경우 | ||
recursive(idx + 1, Math.abs(w - weight[idx])); // 새로운 추를 기존 무게와 뺄 경우 | ||
recursive(idx + 1, w); // 새로운 추를 선택하지 않을 경우 | ||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
N = Integer.parseInt(br.readLine()); | ||
int mx = N * 500; // 주어진 구슬로 확인 가능한 최대 무게 | ||
weight = new int[N+1]; | ||
dp = new boolean[N + 1][(N * 500) + 1]; | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
weight[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
recursive(0, 0); | ||
|
||
int M = Integer.parseInt(br.readLine()); | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < M; i++) { | ||
int mv = Integer.parseInt(st.nextToken()); | ||
if (mv > mx || !dp[N][mv]) sb.append("N").append(" "); | ||
else sb.append("Y").append(" "); | ||
} | ||
System.out.println(sb); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
BOJ/20001-25000번/SB_21758.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,34 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class boj_21758 { | ||
static int N; | ||
static int[] arr; | ||
static int[] sum; | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
N = Integer.parseInt(br.readLine()); | ||
arr = new int[N]; | ||
sum = new int[N]; | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
if (i==0) sum[i] = arr[i]; | ||
else sum[i] += arr[i]+sum[i-1]; | ||
} | ||
|
||
int ans = 0; | ||
for (int i = 1; i < N - 1; i++) { | ||
ans = Math.max(ans, (sum[N - 1] - arr[0] - arr[i]) + (sum[N - 1] - sum[i])); // 벌 벌 꿀 | ||
ans = Math.max(ans, sum[i - 1] + (sum[N - 2] - arr[i])); // 꿀 벌 벌 | ||
ans = Math.max(ans, (sum[i] - arr[0]) + (sum[N - 2] - sum[i - 1])); // 벌 꿀 벌 | ||
} | ||
System.out.println(ans); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
BOJ/30000-35000번/SB_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,48 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class SB_30407 { | ||
static int N, H, D, K; | ||
static int[] attack; | ||
static int ans = 0; | ||
|
||
private static void dfs(int depth, int hp, int d, int atk, boolean isUse) { | ||
if (depth == N) { | ||
ans = Math.max(ans, hp); | ||
return; | ||
} | ||
if (hp <= ans || hp <= 0) return; | ||
|
||
int wounk = Math.max(0, atk - d); | ||
dfs(depth + 1, hp - (wounk / 2), d, attack[depth + 1], isUse); | ||
|
||
int run = Math.max(0, atk - (d + K)); | ||
dfs(depth + 1, hp - run, d + K, attack[depth + 1], isUse); | ||
|
||
if (!isUse) { | ||
int fright = Math.max(0, atk - d); | ||
dfs(depth + 1, hp - fright, d, 0, true); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st; | ||
|
||
N = Integer.parseInt(br.readLine()); | ||
st = new StringTokenizer(br.readLine()); | ||
H = Integer.parseInt(st.nextToken()); // 체력 | ||
D = Integer.parseInt(st.nextToken()); // 거리 | ||
K = Integer.parseInt(st.nextToken()); // 이동 거리 | ||
|
||
attack = new int[N + 1]; | ||
for (int i = 0; i < N; i++) { | ||
attack[i] = Integer.parseInt(br.readLine()); | ||
} | ||
|
||
dfs(0, H, D, attack[0], false); | ||
System.out.println(ans <= 0 ? -1 : ans); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
CodeTree/2023-2024년/SB_코드트리오마카세.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,130 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class SB_코드트리오마카세 { | ||
static int L; | ||
static HashMap<String, List<Sushi>> waitSushi = new HashMap<>(); // 사람 별 먹을 초밥 관리 대기열 | ||
static HashMap<String, Enter> guestInfo = new HashMap<>(); // 손님의 입장 정보 관리 | ||
static int INF = Integer.MAX_VALUE; | ||
static PriorityQueue<Node> pq = new PriorityQueue<>(); // 바로 먹을 초밥 관리 | ||
static int totalSushi = 0; | ||
static int totalGuest = 0; | ||
static StringBuilder sb = new StringBuilder(); | ||
private static int getEatTime(Enter enter, Sushi sushi) { // 손님의 입장 정보와 스시 생성 정보로 먹히는 시간 구하기 | ||
int wait; | ||
if (enter.tm < sushi.tm) { // 손님이 스시보다 빨리옴 | ||
if (enter.pos < sushi.pos) wait = L - sushi.pos + enter.pos; // (초밥이 손님보다 앞에 있음)초밥이 한바퀴 돌아서 손님한테 도착 | ||
else wait = enter.pos - sushi.pos; // (초밥이 손님 뒤에 있음) 손님까지 거리만 이동하면 도착 | ||
return sushi.tm + wait; // 스시가 만들어져서 손님한테 전달되는 시간 | ||
} else { // 스시가 손님보다 먼저 만들어짐 | ||
int afterRotatePos = (sushi.pos + (enter.tm - sushi.tm)) % L; // 손님이 도착할때까지 회전했을때 위치 | ||
if (enter.pos < afterRotatePos) wait = L - afterRotatePos + enter.pos; | ||
else wait = enter.pos - afterRotatePos; | ||
return enter.tm + wait; | ||
} | ||
} | ||
|
||
private static void makeSushi(int t, int x, String name) { // 초밥 만들기 | ||
Sushi sushi = new Sushi(t, x, name, INF); | ||
if (!guestInfo.containsKey(name) || !guestInfo.get(name).isEnter) { // 사람 안왔는데 스시 미리 만듦 | ||
waitSushi.computeIfAbsent(name, k -> new ArrayList<>()).add(sushi); // 스시 대기열에서 대기 | ||
} else { // 사람이 온 후에 스시가 만들어짐 | ||
int eatTime = getEatTime(guestInfo.get(name), sushi); // 회전해서 스시를 먹는 시간 구하기 | ||
pq.offer(new Node(eatTime, name)); // 바로먹을 큐에 삽입 | ||
} | ||
totalSushi++; | ||
} | ||
|
||
private static void enterGuest(int t, int x, String name, int n) { // 손님 입장 | ||
guestInfo.put(name, new Enter(t, x, n)); | ||
totalGuest++; | ||
|
||
if (waitSushi.containsKey(name) && !waitSushi.get(name).isEmpty()) { // 해당 손님의 스시가 있을 경우 스시 먹기 | ||
for (Sushi sushi : waitSushi.get(name)) { | ||
int eatTime = getEatTime(guestInfo.get(name), sushi); | ||
pq.offer(new Node(eatTime, name)); // 바로 먹힐 초밥 관리하는 큐에 정보 저장 | ||
} | ||
waitSushi.get(name).clear(); | ||
} | ||
} | ||
|
||
private static void takePhoto(int t) { // 사진 찍기 겸 진짜 초밥 먹기 | ||
while (!pq.isEmpty()) { | ||
Node node = pq.peek(); | ||
if (node.eatTm > t) break; // 현재 시간보다 늦게 먹히는 초밥이면 그만 | ||
pq.poll(); | ||
totalSushi--; | ||
guestInfo.get(node.guestName).cnt--; // 먹은 초밥수-- | ||
if (guestInfo.get(node.guestName).cnt==0) totalGuest--; // 초밥 다 먹으면 나가기 | ||
} | ||
sb.append(totalGuest).append(" ").append(totalSushi).append("\n"); // 사진 찍기 | ||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
L = Integer.parseInt(st.nextToken()); | ||
int Q = Integer.parseInt(st.nextToken()); | ||
|
||
while (Q-- > 0) { | ||
st = new StringTokenizer(br.readLine()); | ||
int cmd = Integer.parseInt(st.nextToken()); | ||
if (cmd == 100) { | ||
int t = Integer.parseInt(st.nextToken()); | ||
int x = Integer.parseInt(st.nextToken()); | ||
String name = st.nextToken(); | ||
makeSushi(t, x, name); | ||
} else if (cmd == 200) { | ||
int t = Integer.parseInt(st.nextToken()); | ||
int x = Integer.parseInt(st.nextToken()); | ||
String name = st.nextToken(); | ||
int n = Integer.parseInt(st.nextToken()); | ||
enterGuest(t, x, name, n); | ||
} else { | ||
int t = Integer.parseInt(st.nextToken()); | ||
takePhoto(t); | ||
} | ||
} | ||
System.out.println(sb); | ||
} | ||
|
||
static class Sushi{ | ||
int tm, pos, et; // 시간, 초밥 위치, 먹은 시간 | ||
String owner; // 초밥 주인 | ||
|
||
public Sushi(int tm, int pos, String owner, int et) { | ||
this.tm = tm; | ||
this.pos = pos; | ||
this.owner = owner; | ||
this.et = et; | ||
} | ||
} | ||
|
||
static class Enter{ | ||
int tm, pos, cnt; // 시간, 위치, 먹은 개수 | ||
boolean isEnter = true; // 입장여부 | ||
|
||
public Enter(int tm, int pos, int cnt) { | ||
this.tm = tm; | ||
this.pos = pos; | ||
this.cnt = cnt; | ||
} | ||
} | ||
|
||
static class Node implements Comparable<Node>{ | ||
int eatTm; | ||
String guestName; | ||
|
||
public Node(int eatTm, String guestName) { | ||
this.eatTm = eatTm; | ||
this.guestName = guestName; | ||
} | ||
|
||
@Override | ||
public int compareTo(Node o) { | ||
return this.eatTm - o.eatTm; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
Programmers/Level2/SB_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,25 @@ | ||
public class SB_148652 { | ||
private static boolean isOne(long num) { | ||
while (num > 0) { | ||
if (num % 5 == 2) return false; | ||
num /= 5; | ||
} | ||
return true; | ||
} | ||
public static int solution(int n, long l, long r) { | ||
l --; | ||
|
||
int ans = 0; | ||
for (long i = l; i < r; i++) { | ||
if (isOne(i)) ans++; | ||
} | ||
return ans; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int n = 2; | ||
long l = 4; | ||
long r = 17; | ||
System.out.println(solution(n, l, r)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
SQL/24주차/SB_특정 기간동안 대여 가능한 자동차들의 대여비용 구하기.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,23 @@ | ||
-- 자동차 종류가 '세단' 또는 'SUV' 인 자동차 중 | ||
-- 2022년 11월 1일부터 2022년 11월 30일까지 대여 가능하고 | ||
-- 30일간의 대여 금액이 50만원 이상 200만원 미만인 자동차에 대해서 | ||
-- 자동차 ID, 자동차 종류, 대여 금액(컬럼명: FEE) 리스트를 출력하는 SQL문을 작성 | ||
-- 결과는 대여 금액을 기준으로 내림차순 정렬하고, 대여 금액이 같은 경우 자동차 종류를 기준으로 오름차순 정렬, 자동차 종류까지 같은 경우 자동차 ID를 기준으로 내림차순 정렬 | ||
|
||
SELECT A.CAR_ID, A.CAR_TYPE, | ||
ROUND(A.DAILY_FEE*((100-C.DISCOUNT_RATE)/100)*30) AS FEE | ||
FROM CAR_RENTAL_COMPANY_CAR A | ||
JOIN CAR_RENTAL_COMPANY_RENTAL_HISTORY B | ||
ON A.CAR_ID = B.CAR_ID | ||
JOIN CAR_RENTAL_COMPANY_DISCOUNT_PLAN C | ||
ON A.CAR_TYPE = C.CAR_TYPE | ||
WHERE A.CAR_TYPE IN ('세단', 'SUV') | ||
AND A.CAR_ID NOT IN ( | ||
SELECT CAR_ID | ||
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY | ||
WHERE END_DATE > '2022年11月01日' AND START_DATE < '2022年12月01日' | ||
) | ||
AND C.DURATION_TYPE = '30일 이상' | ||
GROUP BY A.CAR_ID | ||
HAVING FEE >= 500000 AND FEE < 2000000 | ||
ORDER BY FEE DESC, A.CAR_TYPE ASC, CAR_ID DESC |
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.