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 1ae18fa

Browse files
Merge pull request #75 from Jewan1120/main
[6주차] 백제완
2 parents a4944a7 + b71ef7b commit 1ae18fa

File tree

9 files changed

+328
-0
lines changed

9 files changed

+328
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import java.util.Arrays;
2+
3+
public class Main {
4+
5+
static int n, c;
6+
static int[] arr;
7+
8+
public static void main(String[] args) throws Exception {
9+
n = read();
10+
c = read();
11+
arr = new int[n];
12+
for (int i = 0; i < n; i++)
13+
arr[i] = read();
14+
Arrays.sort(arr); // 매개 변수 탐색을 위한 정렬
15+
int l = 1, r = arr[n - 1];
16+
// 매개 변수 탐색
17+
while (l <= r) {
18+
int param = (l + r) / 2; // 매개 변수 : 두 공유기 사이의 최소 거리
19+
if (isPossible(param)) {
20+
l = param + 1; // 최소 거리의 최댓값을 찾기 위해 오른쪽 탐색
21+
} else {
22+
r = param - 1; // 해당 거리로는 불가능 했으므로 왼쪽 탐색
23+
}
24+
}
25+
System.out.println(r); // Upper Bound 출력
26+
}
27+
28+
private static boolean isPossible(int param) {
29+
int cnt = 1;
30+
int prev = 0; // 마지막으로 공유기가 설치된 집의 인덱스
31+
for (int i = 1; i < n; i++) {
32+
// 마지막으로 설치된 집과의 거리가 param보다 크다면 공유기 설치
33+
if (arr[i] - arr[prev] >= param) {
34+
cnt++;
35+
prev = i;
36+
}
37+
}
38+
// 많이 설치되도 됨 -> 몇 개 지워버리면 되니깐
39+
return cnt >= c;
40+
}
41+
42+
// 빠른 입력을 위한 함수
43+
private static int read() throws Exception {
44+
int c, n = System.in.read() & 15;
45+
while ((c = System.in.read()) >= 48)
46+
n = (n << 3) + (n << 1) + (c & 15);
47+
if (c == 13)
48+
System.in.read();
49+
return n;
50+
}
51+
}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
public class Main {
2+
3+
static int n, m;
4+
static int[] arr;
5+
6+
public static void main(String[] args) throws Exception {
7+
n = read();
8+
m = read();
9+
arr = new int[n];
10+
int l = 0, r = 0;
11+
for (int i = 0; i < n; i++) {
12+
arr[i] = read();
13+
r = Math.max(r, arr[i]);
14+
}
15+
// 매개 변수 탐색
16+
while (l <= r) {
17+
int target = (l + r) / 2; // 매개 변수 = 절단기의 높이
18+
if (isPossible(target)) {
19+
l = target + 1; // 만족할 수 있었다면 절단기의 높이의 최댓값를 구하기 위해 오른쪽 탐색
20+
} else {
21+
r = target - 1; // 만족할 수 없는 경우 절단기의 높이 줄여야 하므로 왼쪽 탐색
22+
}
23+
}
24+
System.out.println(r); // UpperBound 출력
25+
}
26+
27+
// 해당 절단기의 높이로 자를 수 있는 나무의 총 길이를 구하는 결정함수
28+
private static boolean isPossible(int target) {
29+
long sum = 0;
30+
for (int i = 0; i < n; i++)
31+
sum += Math.max(0, arr[i] - target); // 음수가 될 수 없기 때문에 0으로 제한
32+
// 자른 나무 길이의 총 합이 m 이상이면 가능
33+
return sum >= m;
34+
}
35+
36+
// 빠른 입력을 위한 함수
37+
private static int read() throws Exception {
38+
int c, n = System.in.read() & 15;
39+
while ((c = System.in.read()) >= 48)
40+
n = (n << 3) + (n << 1) + (c & 15);
41+
if (c == 13)
42+
System.in.read();
43+
return n;
44+
}
45+
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
public class Main {
2+
3+
public static void main(String[] args) throws Exception {
4+
int n = read(), m = read();
5+
int[] memories = new int[n];
6+
for (int i = 0; i < n; i++)
7+
memories[i] = read();
8+
int[] costs = new int[n];
9+
int sumCost = 0;
10+
for (int i = 0; i < n; i++) {
11+
costs[i] = read();
12+
sumCost += costs[i];
13+
}
14+
int[][] dp = new int[n + 1][sumCost + 1];
15+
// 0-1 knapsack -> 중복 사용 불가
16+
for (int i = 1; i < n + 1; i++)
17+
// j 비용으로 만들 수 있는 최대 메모리 수 구하기
18+
for (int j = 0; j < sumCost + 1; j++) {
19+
dp[i][j] = dp[i - 1][j];
20+
// 이전 값에서 가져올 수 있다면
21+
if (j >= costs[i - 1]) {
22+
dp[i][j] = Math.max(dp[i][j], memories[i - 1] + dp[i - 1][j - costs[i - 1]]);
23+
}
24+
}
25+
// 처음으로 m 이상이 나오는 금액이 최소 금액
26+
for (int i = 0; i < sumCost + 1; i++)
27+
for (int j = 1; j < n + 1; j++)
28+
if (dp[j][i] >= m) {
29+
System.out.println(i);
30+
return;
31+
}
32+
}
33+
34+
// 빠른 입력 함수
35+
private static int read() throws Exception {
36+
int c, n = System.in.read() & 15;
37+
while ((c = System.in.read()) >= 48)
38+
n = (n << 3) + (n << 1) + (c & 15);
39+
if (c == 13)
40+
System.in.read();
41+
return n;
42+
}
43+
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
public class Main {
2+
3+
public static void main(String[] args) throws Exception {
4+
int t = read();
5+
StringBuilder sb = new StringBuilder();
6+
while (t-- > 0) {
7+
int n = read();
8+
int[] coins = new int[n]; // 동전 단위를 저장하기 위한 배열
9+
for (int i = 0; i < n; i++)
10+
coins[i] = read();
11+
int m = read();
12+
int[] dp = new int[m + 1]; // i의 돈을 만들기 위한 경우의 수를 저장할 배열
13+
dp[0] = 1;
14+
// knapsack - 중복 사용 가능
15+
for (int coin : coins)
16+
// 현재 동전으로 만들 수 있는 조합의 수 계산
17+
for (int i = coin; i < m + 1; i++)
18+
dp[i] += dp[i - coin];
19+
sb.append(dp[m]).append("\n");
20+
}
21+
System.out.println(sb);
22+
}
23+
24+
// 빠른 입력 함수
25+
private static int read() throws Exception {
26+
int c, n = System.in.read() & 15;
27+
while ((c = System.in.read()) >= 48)
28+
n = (n << 3) + (n << 1) + (c & 15);
29+
if (c == 13)
30+
System.in.read();
31+
return n;
32+
}
33+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java.io.BufferedReader;
2+
import java.io.InputStreamReader;
3+
import java.util.StringTokenizer;
4+
5+
public class Main {
6+
7+
static int n, m;
8+
// 도형을 회전, 반전으로 만들 수 있는 모든 경우를 저장
9+
static int[][][] shapes = { { { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 } }, { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 } },
10+
{ { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }, { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 2, 1 } },
11+
{ { 0, 0 }, { 0, 1 }, { 0, 2 }, { -1, 2 } }, { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 } },
12+
{ { 0, 0 }, { 1, 0 }, { 0, 1 }, { 0, 2 } }, { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 2, -1 } },
13+
{ { 0, 0 }, { 0, 1 }, { 0, 2 }, { 1, 2 } }, { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 2, 0 } },
14+
{ { 0, 0 }, { 1, 0 }, { 1, 1 }, { 1, 2 } }, { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 2, 1 } },
15+
{ { 0, 0 }, { 0, 1 }, { -1, 1 }, { -1, 2 } }, { { 0, 0 }, { 1, 0 }, { 1, -1 }, { 2, -1 } },
16+
{ { 0, 0 }, { 0, 1 }, { 1, 1 }, { 1, 2 } }, { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 2, 0 } },
17+
{ { 0, 0 }, { 0, 1 }, { -1, 1 }, { 0, 2 } }, { { 0, 0 }, { 1, 0 }, { 1, -1 }, { 2, 0 } },
18+
{ { 0, 0 }, { 0, 1 }, { 0, 2 }, { 1, 1 } } };
19+
20+
public static void main(String[] args) throws Exception {
21+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22+
StringTokenizer st = new StringTokenizer(br.readLine());
23+
n = Integer.parseInt(st.nextToken());
24+
m = Integer.parseInt(st.nextToken());
25+
int[][] board = new int[n][m];
26+
for (int i = 0; i < n; i++) {
27+
st = new StringTokenizer(br.readLine());
28+
for (int j = 0; j < m; j++)
29+
board[i][j] = Integer.parseInt(st.nextToken());
30+
}
31+
int max = 0;
32+
for (int i = 0; i < n; i++) {
33+
for (int j = 0; j < m; j++) {
34+
// 모든 지점에 대해서 모든 도형을 만들어서 합을 구해줌
35+
for (int[][] shape : shapes) {
36+
int sum = 0;
37+
for (int k = 0; k < 4; k++) {
38+
int y = i + shape[k][0];
39+
int x = j + shape[k][1];
40+
if (isValid(y, x))
41+
sum += board[y][x];
42+
}
43+
max = Math.max(max, sum);
44+
}
45+
}
46+
}
47+
System.out.println(max);
48+
}
49+
50+
// 경계 체크
51+
private static boolean isValid(int y, int x) {
52+
return 0 <= y && y < n && 0 <= x && x < m;
53+
}
54+
}

‎Programmers/Level3/JW_42861.java‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import java.util.ArrayList;
2+
import java.util.PriorityQueue;
3+
class Solution {
4+
5+
// 간선의 정보를 저장할 오브젝트
6+
class Edge {
7+
int to, weight;
8+
9+
Edge(int to, int weight) {
10+
this.to = to;
11+
this.weight = weight;
12+
}
13+
}
14+
15+
public int solution(int n, int[][] costs) {
16+
int answer = 0;
17+
ArrayList<ArrayList<Edge>> edges = new ArrayList<>();
18+
for (int i = 0; i < n; i++)
19+
edges.add(new ArrayList<>());
20+
// 주어진 간선의 정보를 가공하여 저장
21+
for (int[] cost : costs) {
22+
edges.get(cost[0]).add(new Edge(cost[1], cost[2]));
23+
edges.get(cost[1]).add(new Edge(cost[0], cost[2]));
24+
}
25+
// MST - Prim Algorithm
26+
// 간선 비용을 기준으로 오름차순
27+
PriorityQueue<Edge> pq = new PriorityQueue<>((o1, o2) -> o1.weight - o2.weight);
28+
boolean[] visited = new boolean[n];
29+
pq.offer(new Edge(0, 0));
30+
int cnt = 0; // MST를 구성하는 간선은 n-1개면 충분
31+
while (!pq.isEmpty() && cnt < n) {
32+
Edge cur = pq.poll();
33+
if (visited[cur.to])
34+
continue;
35+
visited[cur.to] = true;
36+
cnt++;
37+
answer += cur.weight;
38+
// 방문하지 않은 노드로가는 간선 추가
39+
for (Edge edge : edges.get(cur.to)) {
40+
if (!visited[edge.to])
41+
pq.offer(edge);
42+
}
43+
}
44+
return answer;
45+
}
46+
}

‎Programmers/Level3/JW_43238.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.Arrays;
2+
3+
class Solution {
4+
public long solution(int n, int[] times) {
5+
Arrays.sort(times); // 이분 탐색을 위한 정렬
6+
long l = 1, r = (long) times[times.length - 1] * n; // 가능한 최소, 최대 시간
7+
// 매개 변수 탐색
8+
while (l <= r) {
9+
long m = (l + r) / 2; // 매개 변수
10+
if (isPossible(times, n, m)) { // 결정 함수
11+
// 최솟값을 찾기 위해 왼쪽 탐색
12+
r = m - 1;
13+
} else {
14+
l = m + 1;
15+
}
16+
}
17+
return l; // Lower Bound 반환
18+
}
19+
20+
// 결정 함수 : target 시간에 각각의 심사관이 몇 명을 심사할 수 있는지
21+
private boolean isPossible(int[] times, int n, long target) {
22+
long cnt = 0;
23+
for (int time : times) {
24+
cnt += target / (long) time;
25+
}
26+
return cnt >= n; // n명 이상 심사했다면 true
27+
}
28+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SELECT
2+
A.user_id
3+
, ROUND(AVG(IF(B.action = 'confirmed', 1, 0)), 2) confirmation_rate
4+
FROM
5+
Signups A
6+
LEFT JOIN Confirmations B
7+
ON A.user_id = B.user_id
8+
GROUP BY
9+
A.user_id
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SELECT
2+
A.student_id
3+
, A.student_name
4+
, B.subject_name
5+
, COUNT(C.student_id) attended_exams
6+
FROM
7+
Students A
8+
CROSS JOIN Subjects B
9+
LEFT JOIN Examinations C
10+
ON A.student_id = C.student_id
11+
AND B.subject_name = C.subject_name
12+
GROUP BY
13+
A.student_id
14+
, A.student_name
15+
, B.subject_name
16+
ORDER BY
17+
A.student_id
18+
, A.student_name
19+
, B.subject_name

0 commit comments

Comments
(0)

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