-
Notifications
You must be signed in to change notification settings - Fork 4
[24주차] 손지민 #324
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주차] 손지민 #324
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cbf7a4f
손지민: [CT] 코드트리_오마카세_250225
jmxx219 79dc22b
손지민: [CT] 코드트리_오마카세_250225
jmxx219 d44fbad
손지민 [BOJ] 꿀 따기_250226
jmxx219 9b07138
손지민 [BOJ] 나비의 간식을 훔쳐먹은 춘배_250227
jmxx219 40044a3
손지민 [PG] 유사 칸토어 비트열_250301
jmxx219 989b79a
손지민 [PG] 유사 칸토어 비트열_250301
jmxx219 55f5cfa
손지민 [BOJ] 양팔저울_250301
jmxx219 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
49 changes: 49 additions & 0 deletions
BOJ/1000-5000번/JM_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,49 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class JM_2629 { | ||
static int N; | ||
static int[] W; | ||
static int M; | ||
static int maxW; | ||
static boolean[][] dp; | ||
|
||
private static void solve() { | ||
for (int i = 1; i <= N; i++) { | ||
dp[i][W[i]] = true; | ||
for (int j = 1; j <= maxW; j++) { | ||
if(dp[i - 1][j]) dp[i][j] = true; | ||
if(j + W[i] <= maxW && dp[i - 1][j + W[i]]) dp[i][j] = true; | ||
if(dp[i - 1][Math.abs(j - W[i])]) dp[i][j] = true; | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
N = Integer.parseInt(st.nextToken()); | ||
W = new int[N + 1]; | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 1; i <= N; i++) { | ||
W[i] = Integer.parseInt(st.nextToken()); | ||
maxW += W[i]; | ||
} | ||
|
||
dp = new boolean[N + 1][maxW + 1]; | ||
solve(); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
st = new StringTokenizer(br.readLine()); | ||
M = Integer.parseInt(st.nextToken()); | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < M; i++) { | ||
int bead = Integer.parseInt(st.nextToken()); | ||
if(bead > maxW) sb.append("N").append(" "); | ||
else sb.append(dp[N][bead] ? "Y" : "N").append(" "); | ||
} | ||
System.out.println(sb); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
BOJ/20001-25000번/JM_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,45 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
/** | ||
* 꿀벌(0), 꿀벌(i), 벌통(N-1) | ||
* 벌통(0), 꿀벌(i), 꿀벌(N-1) | ||
* 꿀벌(0), 벌통(i), 꿀벌(N-1) | ||
*/ | ||
public class JM_21758 { | ||
static int N; | ||
static int[] honey; | ||
|
||
private static long solve() { | ||
int[] psum = new int[N]; | ||
|
||
psum[0] = honey[0]; | ||
for (int i = 1; i < N; i++) { | ||
psum[i] += psum[i - 1] + honey[i]; | ||
} | ||
|
||
long maxSum = 0; | ||
for (int i = 1; i < N - 1; i++) { | ||
maxSum = Math.max(maxSum, (psum[N - 1] - honey[0] - honey[i]) + (psum[N - 1] - psum[i])); | ||
maxSum = Math.max(maxSum, (psum[i - 1]) + (psum[N - 1] - honey[i] - honey[N - 1])); | ||
maxSum = Math.max(maxSum, (psum[i] - honey[0]) + (psum[N - 1] - psum[i - 1] - honey[N - 1])); | ||
} | ||
return maxSum; | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
N = Integer.parseInt(st.nextToken()); | ||
honey = new int[N]; | ||
|
||
|
||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
honey[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
System.out.println(solve()); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
BOJ/30000-35000번/JM_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,60 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class JM_30407 { | ||
static int N; // 냥냥펀치 수 | ||
static int H; // 춘배의 체력 | ||
static int D; // 현재 나비 사이의 거리 D | ||
static int K; // 네발로 걷기 시, 이동하는 거리 | ||
static int[] R; | ||
static int maxH; | ||
|
||
public static void dfs(int rIdx, int currH, int dist, boolean surprise) { | ||
if(currH <= maxH) return; | ||
if(rIdx == N) { | ||
maxH = Math.max(maxH, currH); | ||
return; | ||
} | ||
|
||
// 웅크리기 | ||
int punch = (R[rIdx] - dist) > 0 ? (R[rIdx] - dist) : 0; | ||
int damage = punch / 2; | ||
dfs(rIdx + 1, currH - damage, dist, surprise); | ||
|
||
|
||
// 네발로 걷기 | ||
int nextDist = dist + K; | ||
damage = (R[rIdx] - nextDist) > 0 ? (R[rIdx] - nextDist) : 0; | ||
dfs(rIdx + 1, currH - damage, nextDist, surprise); | ||
|
||
// 깜짝 놀라게 하기 | ||
if(surprise && rIdx < N - 1) { | ||
int tmpR = R[rIdx + 1]; | ||
R[rIdx + 1] = 0; | ||
dfs(rIdx + 1, currH - punch, dist, !surprise); | ||
R[rIdx + 1] = tmpR; | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
N = Integer.parseInt(st.nextToken()); | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
H = Integer.parseInt(st.nextToken()); | ||
D = Integer.parseInt(st.nextToken()); | ||
K = Integer.parseInt(st.nextToken()); | ||
|
||
R = new int[N]; | ||
for (int i = 0; i < N; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
R[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
dfs(0, H, D, true); | ||
System.out.println(maxH <= 0 ? -1 : maxH); | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
CodeTree/2023-2024년/JM_코드트리_오마카세.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,160 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.StringTokenizer; | ||
|
||
/** | ||
* 28%에서 틀렸던 이유: 사람이 나가는 시간을 MAX로 Update 안해줌 | ||
*/ | ||
public class JM_코드트리_오마카세 { | ||
static class Sushi { | ||
int time; | ||
int pos; | ||
String name; | ||
|
||
public Sushi(int time, int pos, String name) { | ||
this.time = time; | ||
this.pos = pos; | ||
this.name = name; | ||
} | ||
} | ||
static class Person { | ||
int time; | ||
int pos; | ||
String name; | ||
int n; | ||
int maxOutTime; | ||
public Person(int time, int pos, String name, int n) { | ||
this.time = time; | ||
this.pos = pos; | ||
this.name = name; | ||
this.n = n; | ||
} | ||
} | ||
static class Time implements Comparable<Time> { | ||
int time; | ||
char command; | ||
boolean isOutTime; | ||
|
||
public Time(int time, char command, boolean isOutTime) { | ||
this.time = time; | ||
this.command = command; | ||
this.isOutTime = isOutTime; | ||
} | ||
|
||
@Override | ||
public int compareTo(Time o) { | ||
if(this.time == o.time){ | ||
if (this.command == 'T' && o.command != 'T') return 1; | ||
if (this.command != 'T' && o.command == 'T') return -1; | ||
return 0; | ||
} | ||
return this.time - o.time; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Time{" + | ||
"time=" + time + | ||
", command=" + command + | ||
", isOutTime=" + isOutTime + | ||
'}'; | ||
} | ||
} | ||
static int L; // 초밥 벨트의 길이 | ||
static int Q; // 명령의 수 | ||
static Map<String, Person> persons; | ||
static List<Sushi> sushi; | ||
static List<Time> times; | ||
|
||
private static List<Time> findOutTime() { | ||
for(Sushi s: sushi) { | ||
Person person = persons.get(s.name); | ||
int outTime = s.time; | ||
int outPos = s.pos; | ||
|
||
if(s.time < person.time) { // 스시가 먼저 도착한 경우 | ||
outPos = ((person.time - s.time) + s.pos) % L; // 사람의 시간과 스시 시간 맞춰서 이동 | ||
outTime = person.time; | ||
} | ||
|
||
if(outPos <= person.pos) outTime += (person.pos - outPos); | ||
else if(outPos > person.pos) outTime += L - (outPos - person.pos); | ||
|
||
times.add(new Time(outTime, 'S', true)); | ||
person.n--; | ||
person.maxOutTime = Math.max(person.maxOutTime, outTime); | ||
if(person.n == 0) times.add(new Time(person.maxOutTime, 'P', true)); | ||
} | ||
return times; | ||
} | ||
|
||
public static String solve() { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
findOutTime(); | ||
Collections.sort(times); | ||
|
||
int sushiCount = 0; | ||
int personCount = 0; | ||
for(Time t : times) { | ||
switch (t.command) { | ||
case 'T': | ||
sb.append(personCount).append(" ") | ||
.append(sushiCount).append("\n"); | ||
break; | ||
case 'P': | ||
if(t.isOutTime) personCount--; | ||
else personCount++; | ||
break; | ||
case 'S': | ||
if(t.isOutTime) sushiCount--; | ||
else sushiCount++; | ||
break; | ||
} | ||
} | ||
|
||
return sb.toString(); | ||
} | ||
|
||
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()); | ||
Q = Integer.parseInt(st.nextToken()); | ||
|
||
persons = new HashMap<>(); | ||
sushi = new ArrayList<>(); | ||
times = new ArrayList<>(); | ||
|
||
for (int i = 0; i < Q; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int command = Integer.parseInt(st.nextToken()); | ||
if(command == 100){ | ||
int t = Integer.parseInt(st.nextToken()); | ||
int x = Integer.parseInt(st.nextToken()); | ||
String name = st.nextToken(); | ||
sushi.add(new Sushi(t, x, name)); | ||
times.add(new Time(t, 'S', false)); | ||
} | ||
else if (command == 200) { | ||
int t = Integer.parseInt(st.nextToken()); | ||
int x = Integer.parseInt(st.nextToken()); | ||
String name = st.nextToken(); | ||
int n = Integer.parseInt(st.nextToken()); | ||
persons.put(name, new Person(t, x, name, n)); | ||
times.add(new Time(t, 'P', false)); | ||
} | ||
else { | ||
int t = Integer.parseInt(st.nextToken()); | ||
times.add(new Time(t, 'T', false)); | ||
} | ||
} | ||
System.out.println(solve()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
Programmers/Level2/JM_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,19 @@ | ||
|
||
class JM_148652 { | ||
private static int getIndex(long i) { | ||
while (i > 0) { | ||
if(i % 5 == 2) return 2; | ||
i /= 5; | ||
} | ||
return (int) i; | ||
} | ||
|
||
public static int solution(int n, long l, long r) { | ||
int[] mapping = {1, 1, 0, 1, 1}; | ||
int answer = 0; | ||
for(long i = l - 1; i <= r - 1; i++) { | ||
answer += mapping[getIndex(i)]; | ||
} | ||
return answer; | ||
} | ||
} |
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.