Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit de82e79

Browse files
committed
week 34
1 parent f58c716 commit de82e79

File tree

6 files changed

+296
-0
lines changed

6 files changed

+296
-0
lines changed

thursday/week33/jinu/BOJ1072.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
public class BOJ1072 {
66

7+
// Y /X ∗100=Z이고, 판수를 더 올려 승률이 Z에서 변화하게 될 때의 승률은 무조건 감소하지 않고 증가합니다.
8+
// 그래서 판 수(X) 와 이긴 횟수(Y)를 mid 만큼 늘려 승률을 계산합니다.
9+
// 결과적으로 승률에 변동이 생기면, 해당 횟수 answer 에 담고, 더 적은 횟수로 승률 변동이 있는지 확인하기 위해 상한값을 조정하고
10+
// 변동이 없다면, 더 많은 게임 횟수 범위 내를 확인하기 위해 하한값을 조정
11+
712
static int X, Y, Z;
813

914
public static void main(String[] args) {

thursday/week34/jinu/BOJ1475.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package thursday.week34.jinu;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class BOJ1475 {
7+
8+
public static void main(String[] args) throws Exception {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
String N = br.readLine();
11+
int[] numSet = new int[10];
12+
for (char c : N.toCharArray()) {
13+
int num = c - '0';
14+
if (num == 9) {
15+
num = 6;
16+
}
17+
numSet[num]++;
18+
}
19+
20+
// 6과 9는 바꿀 수 있으므로 2로 나눔
21+
numSet[6] = numSet[6] / 2 + numSet[6] % 2;
22+
23+
Arrays.sort(numSet);
24+
// 오름차순 정렬이므로 마지막 요소 출력
25+
System.out.println(numSet[9]);
26+
}
27+
}

thursday/week34/jinu/BOJ1757.java

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

thursday/week34/jinu/BOJ2477.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package thursday.week34.jinu;
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
public class BOJ2477 {
7+
8+
public static void main(String[] args) throws IOException {
9+
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
StringTokenizer st;
12+
13+
int N = Integer.parseInt(br.readLine());
14+
int[] arr = new int[6];
15+
int MaxWidthI = 0, MaxWidth = 0, MaxHeight = 0, MaxHeightI = 0, d;
16+
for (int i = 0; i < 6; i++) {
17+
st = new StringTokenizer(br.readLine());
18+
d = Integer.parseInt(st.nextToken());
19+
arr[i] = Integer.parseInt(st.nextToken());
20+
21+
// 가장 긴 가로의 길이와 위치 찾기
22+
if ((d == 1 || d == 2) && MaxWidth < arr[i]) {
23+
MaxWidth = arr[i];
24+
MaxWidthI = i;
25+
}
26+
27+
// 가장 긴 세로의 길이와 위치 찾기
28+
else if ((d == 3 || d == 4) && MaxHeight < arr[i]) {
29+
MaxHeight = arr[i];
30+
MaxHeightI = i;
31+
}
32+
}
33+
34+
int right, left, minWidth, minHeight;
35+
36+
if (MaxWidthI + 1 == 6) {
37+
right = 0;
38+
} else {
39+
right = MaxWidthI + 1;
40+
}
41+
42+
if (MaxWidthI - 1 == -1) {
43+
left = 5;
44+
} else {
45+
left = MaxWidthI - 1;
46+
}
47+
48+
minHeight = Math.abs(arr[right] - arr[left]);
49+
50+
if (MaxHeightI + 1 == 6) {
51+
right = 0;
52+
} else {
53+
right = MaxHeight + 1;
54+
}
55+
56+
if (MaxHeightI - 1 == -1) {
57+
left = 5;
58+
} else {
59+
left = MaxHeightI - 1;
60+
}
61+
62+
// 빈 사각형의 가로 길이
63+
minWidth = Math.abs(arr[right] - arr[left]);
64+
65+
System.out.println(((MaxWidth + MaxHeight) - (minHeight + minWidth)) * N);
66+
67+
}
68+
69+
}

thursday/week34/jinu/BOJ6118.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package thursday.week34.jinu;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class BOJ6118 {
7+
8+
public static void main(String[] args) throws Exception {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
StringBuilder sb = new StringBuilder();
11+
12+
int num, line;
13+
int one, two;
14+
int[] maxIdx = new int[3];
15+
Queue<Point> queue = new LinkedList<>();
16+
boolean[] visited;
17+
ArrayList<ArrayList<Integer>> list = new ArrayList<>();
18+
StringTokenizer st = new StringTokenizer(br.readLine());
19+
20+
num = Integer.parseInt(st.nextToken());
21+
line = Integer.parseInt(st.nextToken());
22+
23+
visited = new boolean[num + 1];
24+
25+
for (int x = 0; x <= num; x++) {
26+
list.add(new ArrayList<>());
27+
}
28+
29+
for (int x = 0; x < line; x++) {
30+
st = new StringTokenizer(br.readLine());
31+
32+
one = Integer.parseInt(st.nextToken());
33+
two = Integer.parseInt(st.nextToken());
34+
35+
list.get(one).add(two);
36+
list.get(two).add(one);
37+
}
38+
39+
queue.add(new Point(1, 0));
40+
visited[1] = true;
41+
42+
while (!queue.isEmpty()) {
43+
Point now = queue.poll();
44+
45+
// 최대 거리 계산
46+
if (now.move > maxIdx[1]) {
47+
maxIdx[0] = now.edge;
48+
maxIdx[1] = now.move;
49+
maxIdx[2] = 1;
50+
} else if (now.move == maxIdx[1]) {
51+
maxIdx[2]++;
52+
maxIdx[0] = Math.min(maxIdx[0], now.edge);
53+
}
54+
55+
// 다음 노드 탐색
56+
for (int x : list.get(now.edge)) {
57+
if (visited[x])
58+
continue;
59+
60+
visited[x] = true;
61+
queue.add(new Point(x, now.move + 1));
62+
}
63+
}
64+
65+
for (int x : maxIdx)
66+
sb.append(x).append(" ");
67+
68+
System.out.println(sb);
69+
70+
}
71+
72+
public static class Point {
73+
int edge, move;
74+
75+
Point(int edge, int move) {
76+
this.edge = edge;
77+
this.move = move;
78+
}
79+
}
80+
81+
}

thursday/week34/jinu/BOJ6497.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package thursday.week34.jinu;
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
public class BOJ6497 {
7+
8+
static int[] parent;
9+
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
13+
while (true) {
14+
15+
String[] inputs = br.readLine().split(" ");
16+
17+
int m = Integer.parseInt(inputs[0]);
18+
int n = Integer.parseInt(inputs[1]);
19+
if (m == 0 && n == 0) {
20+
return;
21+
}
22+
23+
int[][] edges = new int[n][3];
24+
25+
int total_cost = 0;
26+
for (int i = 0; i < n; i++) {
27+
inputs = br.readLine().split(" ");
28+
29+
int x = Integer.parseInt(inputs[0]);
30+
int y = Integer.parseInt(inputs[1]);
31+
int z = Integer.parseInt(inputs[2]);
32+
33+
edges[i][0] = x;
34+
edges[i][1] = y;
35+
edges[i][2] = z;
36+
37+
total_cost += edges[i][2];
38+
39+
}
40+
41+
Arrays.sort(edges, (a, b) -> a[2] - b[2]);
42+
43+
parent = new int[m + 1];
44+
for (int i = 1; i <= m; i++) {
45+
parent[i] = i;
46+
}
47+
48+
int min_cost = 0;
49+
int selected_cnt = 0;
50+
int i = 0;
51+
while (true) {
52+
if (find(edges[i][0]) != find(edges[i][1])) {
53+
union(edges[i][0], edges[i][1]);
54+
min_cost += edges[i][2];
55+
selected_cnt++;
56+
}
57+
if (selected_cnt == m - 1) {
58+
break;
59+
}
60+
i++;
61+
}
62+
System.out.println(total_cost - min_cost);
63+
}
64+
65+
}
66+
67+
public static int find(int idx) {
68+
if (parent[idx] == idx) {
69+
return idx;
70+
}
71+
parent[idx] = find(parent[idx]);
72+
return parent[idx];
73+
}
74+
75+
public static void union(int a, int b) {
76+
int parent_of_a = find(a);
77+
parent[parent_of_a] = b;
78+
}
79+
80+
}

0 commit comments

Comments
 (0)