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 bb0a1ae

Browse files
authored
Merge pull request #324 from GreatAlgorithm-Study/jimin
[24주차] 손지민
2 parents 9e2cf6e + 55f5cfa commit bb0a1ae

File tree

5 files changed

+333
-0
lines changed

5 files changed

+333
-0
lines changed

‎BOJ/1000-5000번/JM_2629.java‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class JM_2629 {
7+
static int N;
8+
static int[] W;
9+
static int M;
10+
static int maxW;
11+
static boolean[][] dp;
12+
13+
private static void solve() {
14+
for (int i = 1; i <= N; i++) {
15+
dp[i][W[i]] = true;
16+
for (int j = 1; j <= maxW; j++) {
17+
if(dp[i - 1][j]) dp[i][j] = true;
18+
if(j + W[i] <= maxW && dp[i - 1][j + W[i]]) dp[i][j] = true;
19+
if(dp[i - 1][Math.abs(j - W[i])]) dp[i][j] = true;
20+
}
21+
}
22+
}
23+
24+
public static void main(String[] args) throws IOException {
25+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
26+
StringTokenizer st = new StringTokenizer(br.readLine());
27+
N = Integer.parseInt(st.nextToken());
28+
W = new int[N + 1];
29+
st = new StringTokenizer(br.readLine());
30+
for (int i = 1; i <= N; i++) {
31+
W[i] = Integer.parseInt(st.nextToken());
32+
maxW += W[i];
33+
}
34+
35+
dp = new boolean[N + 1][maxW + 1];
36+
solve();
37+
38+
StringBuilder sb = new StringBuilder();
39+
st = new StringTokenizer(br.readLine());
40+
M = Integer.parseInt(st.nextToken());
41+
st = new StringTokenizer(br.readLine());
42+
for (int i = 0; i < M; i++) {
43+
int bead = Integer.parseInt(st.nextToken());
44+
if(bead > maxW) sb.append("N").append(" ");
45+
else sb.append(dp[N][bead] ? "Y" : "N").append(" ");
46+
}
47+
System.out.println(sb);
48+
}
49+
}

‎BOJ/20001-25000번/JM_21758.java‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
/**
7+
* 꿀벌(0), 꿀벌(i), 벌통(N-1)
8+
* 벌통(0), 꿀벌(i), 꿀벌(N-1)
9+
* 꿀벌(0), 벌통(i), 꿀벌(N-1)
10+
*/
11+
public class JM_21758 {
12+
static int N;
13+
static int[] honey;
14+
15+
private static long solve() {
16+
int[] psum = new int[N];
17+
18+
psum[0] = honey[0];
19+
for (int i = 1; i < N; i++) {
20+
psum[i] += psum[i - 1] + honey[i];
21+
}
22+
23+
long maxSum = 0;
24+
for (int i = 1; i < N - 1; i++) {
25+
maxSum = Math.max(maxSum, (psum[N - 1] - honey[0] - honey[i]) + (psum[N - 1] - psum[i]));
26+
maxSum = Math.max(maxSum, (psum[i - 1]) + (psum[N - 1] - honey[i] - honey[N - 1]));
27+
maxSum = Math.max(maxSum, (psum[i] - honey[0]) + (psum[N - 1] - psum[i - 1] - honey[N - 1]));
28+
}
29+
return maxSum;
30+
}
31+
32+
public static void main(String[] args) throws IOException {
33+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
34+
StringTokenizer st = new StringTokenizer(br.readLine());
35+
N = Integer.parseInt(st.nextToken());
36+
honey = new int[N];
37+
38+
39+
st = new StringTokenizer(br.readLine());
40+
for (int i = 0; i < N; i++) {
41+
honey[i] = Integer.parseInt(st.nextToken());
42+
}
43+
System.out.println(solve());
44+
}
45+
}

‎BOJ/30000-35000번/JM_30407.java‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class JM_30407 {
7+
static int N; // 냥냥펀치 수
8+
static int H; // 춘배의 체력
9+
static int D; // 현재 나비 사이의 거리 D
10+
static int K; // 네발로 걷기 시, 이동하는 거리
11+
static int[] R;
12+
static int maxH;
13+
14+
public static void dfs(int rIdx, int currH, int dist, boolean surprise) {
15+
if(currH <= maxH) return;
16+
if(rIdx == N) {
17+
maxH = Math.max(maxH, currH);
18+
return;
19+
}
20+
21+
// 웅크리기
22+
int punch = (R[rIdx] - dist) > 0 ? (R[rIdx] - dist) : 0;
23+
int damage = punch / 2;
24+
dfs(rIdx + 1, currH - damage, dist, surprise);
25+
26+
27+
// 네발로 걷기
28+
int nextDist = dist + K;
29+
damage = (R[rIdx] - nextDist) > 0 ? (R[rIdx] - nextDist) : 0;
30+
dfs(rIdx + 1, currH - damage, nextDist, surprise);
31+
32+
// 깜짝 놀라게 하기
33+
if(surprise && rIdx < N - 1) {
34+
int tmpR = R[rIdx + 1];
35+
R[rIdx + 1] = 0;
36+
dfs(rIdx + 1, currH - punch, dist, !surprise);
37+
R[rIdx + 1] = tmpR;
38+
}
39+
}
40+
41+
public static void main(String[] args) throws IOException {
42+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
43+
StringTokenizer st = new StringTokenizer(br.readLine());
44+
N = Integer.parseInt(st.nextToken());
45+
46+
st = new StringTokenizer(br.readLine());
47+
H = Integer.parseInt(st.nextToken());
48+
D = Integer.parseInt(st.nextToken());
49+
K = Integer.parseInt(st.nextToken());
50+
51+
R = new int[N];
52+
for (int i = 0; i < N; i++) {
53+
st = new StringTokenizer(br.readLine());
54+
R[i] = Integer.parseInt(st.nextToken());
55+
}
56+
57+
dfs(0, H, D, true);
58+
System.out.println(maxH <= 0 ? -1 : maxH);
59+
}
60+
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.ArrayList;
5+
import java.util.Collections;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.StringTokenizer;
10+
11+
/**
12+
* 28%에서 틀렸던 이유: 사람이 나가는 시간을 MAX로 Update 안해줌
13+
*/
14+
public class JM_코드트리_오마카세 {
15+
static class Sushi {
16+
int time;
17+
int pos;
18+
String name;
19+
20+
public Sushi(int time, int pos, String name) {
21+
this.time = time;
22+
this.pos = pos;
23+
this.name = name;
24+
}
25+
}
26+
static class Person {
27+
int time;
28+
int pos;
29+
String name;
30+
int n;
31+
int maxOutTime;
32+
public Person(int time, int pos, String name, int n) {
33+
this.time = time;
34+
this.pos = pos;
35+
this.name = name;
36+
this.n = n;
37+
}
38+
}
39+
static class Time implements Comparable<Time> {
40+
int time;
41+
char command;
42+
boolean isOutTime;
43+
44+
public Time(int time, char command, boolean isOutTime) {
45+
this.time = time;
46+
this.command = command;
47+
this.isOutTime = isOutTime;
48+
}
49+
50+
@Override
51+
public int compareTo(Time o) {
52+
if(this.time == o.time){
53+
if (this.command == 'T' && o.command != 'T') return 1;
54+
if (this.command != 'T' && o.command == 'T') return -1;
55+
return 0;
56+
}
57+
return this.time - o.time;
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return "Time{" +
63+
"time=" + time +
64+
", command=" + command +
65+
", isOutTime=" + isOutTime +
66+
'}';
67+
}
68+
}
69+
static int L; // 초밥 벨트의 길이
70+
static int Q; // 명령의 수
71+
static Map<String, Person> persons;
72+
static List<Sushi> sushi;
73+
static List<Time> times;
74+
75+
private static List<Time> findOutTime() {
76+
for(Sushi s: sushi) {
77+
Person person = persons.get(s.name);
78+
int outTime = s.time;
79+
int outPos = s.pos;
80+
81+
if(s.time < person.time) { // 스시가 먼저 도착한 경우
82+
outPos = ((person.time - s.time) + s.pos) % L; // 사람의 시간과 스시 시간 맞춰서 이동
83+
outTime = person.time;
84+
}
85+
86+
if(outPos <= person.pos) outTime += (person.pos - outPos);
87+
else if(outPos > person.pos) outTime += L - (outPos - person.pos);
88+
89+
times.add(new Time(outTime, 'S', true));
90+
person.n--;
91+
person.maxOutTime = Math.max(person.maxOutTime, outTime);
92+
if(person.n == 0) times.add(new Time(person.maxOutTime, 'P', true));
93+
}
94+
return times;
95+
}
96+
97+
public static String solve() {
98+
StringBuilder sb = new StringBuilder();
99+
100+
findOutTime();
101+
Collections.sort(times);
102+
103+
int sushiCount = 0;
104+
int personCount = 0;
105+
for(Time t : times) {
106+
switch (t.command) {
107+
case 'T':
108+
sb.append(personCount).append(" ")
109+
.append(sushiCount).append("\n");
110+
break;
111+
case 'P':
112+
if(t.isOutTime) personCount--;
113+
else personCount++;
114+
break;
115+
case 'S':
116+
if(t.isOutTime) sushiCount--;
117+
else sushiCount++;
118+
break;
119+
}
120+
}
121+
122+
return sb.toString();
123+
}
124+
125+
public static void main(String[] args) throws IOException {
126+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
127+
StringTokenizer st = new StringTokenizer(br.readLine());
128+
L = Integer.parseInt(st.nextToken());
129+
Q = Integer.parseInt(st.nextToken());
130+
131+
persons = new HashMap<>();
132+
sushi = new ArrayList<>();
133+
times = new ArrayList<>();
134+
135+
for (int i = 0; i < Q; i++) {
136+
st = new StringTokenizer(br.readLine());
137+
int command = Integer.parseInt(st.nextToken());
138+
if(command == 100){
139+
int t = Integer.parseInt(st.nextToken());
140+
int x = Integer.parseInt(st.nextToken());
141+
String name = st.nextToken();
142+
sushi.add(new Sushi(t, x, name));
143+
times.add(new Time(t, 'S', false));
144+
}
145+
else if (command == 200) {
146+
int t = Integer.parseInt(st.nextToken());
147+
int x = Integer.parseInt(st.nextToken());
148+
String name = st.nextToken();
149+
int n = Integer.parseInt(st.nextToken());
150+
persons.put(name, new Person(t, x, name, n));
151+
times.add(new Time(t, 'P', false));
152+
}
153+
else {
154+
int t = Integer.parseInt(st.nextToken());
155+
times.add(new Time(t, 'T', false));
156+
}
157+
}
158+
System.out.println(solve());
159+
}
160+
}

‎Programmers/Level2/JM_148652.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
class JM_148652 {
3+
private static int getIndex(long i) {
4+
while (i > 0) {
5+
if(i % 5 == 2) return 2;
6+
i /= 5;
7+
}
8+
return (int) i;
9+
}
10+
11+
public static int solution(int n, long l, long r) {
12+
int[] mapping = {1, 1, 0, 1, 1};
13+
int answer = 0;
14+
for(long i = l - 1; i <= r - 1; i++) {
15+
answer += mapping[getIndex(i)];
16+
}
17+
return answer;
18+
}
19+
}

0 commit comments

Comments
(0)

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