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주차] 손지민 #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
KodaHye merged 7 commits into main from jimin
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
49 changes: 49 additions & 0 deletions BOJ/1000-5000번/JM_2629.java
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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;
}
}

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