Skip to content

Commit c7a2eaa

Browse files
committed
feat: 35주차 완료
1 parent 2716a68 commit c7a2eaa

File tree

4 files changed

+287
-0
lines changed

4 files changed

+287
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package week35.강성욱.baekjoon;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
/**
9+
* PackageName : week35.강성욱.baekjoon
10+
* FileName : 근손실
11+
* Author : Baekgwa
12+
* Date : 25. 12. 30.
13+
* Description :
14+
* =====================================================================================================================
15+
* DATE AUTHOR NOTE
16+
* ---------------------------------------------------------------------------------------------------------------------
17+
* 25. 12. 30. Baekgwa Initial creation
18+
*/
19+
public class 근손실 {
20+
public class Main {
21+
22+
// 모든 케이스를 다 확인하면?
23+
// 최대 8개 운동키트 순열 8!
24+
// 4만
25+
// 한 조합당 확인해야 하는 횟수 8번
26+
// 32만
27+
// 할만한듯?
28+
29+
private static int[] list;
30+
private static boolean[] visited;
31+
private static int K;
32+
private static int N;
33+
private static int count = 0;
34+
35+
public static void main(String[] args) throws IOException {
36+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
37+
StringTokenizer st = new StringTokenizer(br.readLine());
38+
39+
N = Integer.parseInt(st.nextToken());
40+
K = Integer.parseInt(st.nextToken());
41+
42+
list = new int[N];
43+
visited = new boolean[N];
44+
45+
st = new StringTokenizer(br.readLine());
46+
for (int i = 0; i < N; i++) {
47+
list[i] = Integer.parseInt(st.nextToken());
48+
}
49+
50+
dfs(0, 500);
51+
System.out.println(count);
52+
}
53+
54+
private static void dfs(int day, int weight) {
55+
if(weight < 500) {
56+
return;
57+
}
58+
59+
if(day == N) {
60+
count++;
61+
return;
62+
}
63+
64+
for(int i=0; i<N; i++) {
65+
if(visited[i]) continue;
66+
67+
visited[i] = true;
68+
dfs(day+1, weight + list[i] - K);
69+
visited[i] = false;
70+
}
71+
}
72+
}
73+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package week35.강성욱.baekjoon;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
/**
9+
* PackageName : week35.강성욱.baekjoon
10+
* FileName : 돌_게임_nm
11+
* Author : Baekgwa
12+
* Date : 25. 12. 30.
13+
* Description :
14+
* =====================================================================================================================
15+
* DATE AUTHOR NOTE
16+
* ---------------------------------------------------------------------------------------------------------------------
17+
* 25. 12. 30. Baekgwa Initial creation
18+
*/
19+
public class 돌_게임_nm {
20+
public class Main {
21+
22+
// 음 항상 더 큰곳을 고르는게 승리에 영향이 있는건가?
23+
// ㄴㄴ 3x3 에서 더 큰곳을 고르면, 3줄밖에 못긋는데, 중간에 작은곳을 한번 선택하면 승패가 바뀜
24+
// 그럼 더 짧은곳을 고르는게 승리에 영향이 있는가?
25+
// 근데 이거 시뮬레이션 아닌듯? n,m 의 범위가 너무 큰데?
26+
// 바로 공식으로 딱 나오는거일듯
27+
// 결국 정사각형으로 시작하는 사람이 지는 게임
28+
29+
public static void main(String[] args) throws IOException {
30+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
31+
32+
int T = Integer.parseInt(br.readLine());
33+
34+
for (int i = 0; i < T; i++) {
35+
StringTokenizer st = new StringTokenizer(br.readLine());
36+
long n = Long.parseLong(st.nextToken());
37+
long m = Long.parseLong(st.nextToken());
38+
39+
if (Math.min(n, m) >= 2 && (n - m) % 2 == 0) {
40+
System.out.println("NO");
41+
} else {
42+
System.out.println("YES");
43+
}
44+
}
45+
}
46+
}
47+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package week35.강성욱.baekjoon;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
/**
9+
* PackageName : week35.강성욱.baekjoon
10+
* FileName : 서강그라운드
11+
* Author : Baekgwa
12+
* Date : 25. 12. 30.
13+
* Description :
14+
* =====================================================================================================================
15+
* DATE AUTHOR NOTE
16+
* ---------------------------------------------------------------------------------------------------------------------
17+
* 25. 12. 30. Baekgwa Initial creation
18+
*/
19+
public class 서강그라운드 {
20+
public class Main {
21+
public static void main(String[] args) throws IOException {
22+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
23+
StringTokenizer st = new StringTokenizer(br.readLine());
24+
25+
int n = Integer.parseInt(st.nextToken());
26+
int m = Integer.parseInt(st.nextToken());
27+
int r = Integer.parseInt(st.nextToken());
28+
29+
int[] items = new int[n + 1];
30+
st = new StringTokenizer(br.readLine());
31+
for (int i = 1; i <= n; i++) {
32+
items[i] = Integer.parseInt(st.nextToken());
33+
}
34+
35+
int[][] dist = new int[n + 1][n + 1];
36+
37+
for (int i = 1; i <= n; i++) {
38+
for (int j = 1; j <= n; j++) {
39+
if (i == j)
40+
dist[i][j] = 0;
41+
else
42+
dist[i][j] = Integer.MAX_VALUE;
43+
}
44+
}
45+
46+
for (int i = 0; i < r; i++) {
47+
st = new StringTokenizer(br.readLine());
48+
int a = Integer.parseInt(st.nextToken());
49+
int b = Integer.parseInt(st.nextToken());
50+
int l = Integer.parseInt(st.nextToken());
51+
52+
dist[a][b] = Math.min(dist[a][b], l);
53+
dist[b][a] = Math.min(dist[b][a], l);
54+
}
55+
56+
for (int k = 1; k <= n; k++) {
57+
for (int i = 1; i <= n; i++) {
58+
for (int j = 1; j <= n; j++) {
59+
if (dist[i][j] > dist[i][k] + dist[k][j]) {
60+
dist[i][j] = dist[i][k] + dist[k][j];
61+
}
62+
}
63+
}
64+
}
65+
66+
int max = 0;
67+
68+
// 각 지역을 시작점으로 아이템 합 계산
69+
for (int start = 1; start <= n; start++) {
70+
int sum = 0;
71+
for (int end = 1; end <= n; end++) {
72+
if (dist[start][end] <= m) {
73+
sum += items[end];
74+
}
75+
}
76+
max = Math.max(max, sum);
77+
}
78+
79+
System.out.println(max);
80+
}
81+
}
82+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package week35.강성욱.baekjoon;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.LinkedList;
7+
import java.util.Queue;
8+
9+
/**
10+
* PackageName : week35.강성욱.baekjoon
11+
* FileName : 적록색약
12+
* Author : Baekgwa
13+
* Date : 25. 12. 30.
14+
* Description :
15+
* =====================================================================================================================
16+
* DATE AUTHOR NOTE
17+
* ---------------------------------------------------------------------------------------------------------------------
18+
* 25. 12. 30. Baekgwa Initial creation
19+
*/
20+
public class 적록색약 {
21+
public class Main {
22+
23+
private static int N;
24+
private static char[][] map;
25+
private static int[] dx = {-1, 0, 1, 0};
26+
private static int[] dy = {0, -1, 0, 1};
27+
28+
public static void main(String[] args) throws IOException {
29+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
30+
N = Integer.parseInt(br.readLine());
31+
map = new char[N][N];
32+
for(int i=0; i<N; i++) {
33+
map[i] = br.readLine().toCharArray();
34+
}
35+
36+
int normalCount = bfs(true);
37+
int abnormalCount = bfs(false);
38+
39+
System.out.println(normalCount + " " + abnormalCount);
40+
}
41+
42+
public static int bfs(boolean isNormal) {
43+
int count = 0;
44+
boolean[][] visited = new boolean[N][N];
45+
46+
// x, y 모두 돌면서 최대한 다 확인하기
47+
for(int y=0; y<N; y++) {
48+
for(int x=0; x<N; x++) {
49+
char nowChar = map[y][x];
50+
Queue<int[]> q = new LinkedList<>();
51+
52+
// 이미 방문한 곳이면 pass (다른 구역에 포함되면)
53+
if(visited[y][x]) continue;
54+
q.offer(new int[]{y, x});
55+
visited[y][x] = true;
56+
57+
while(!q.isEmpty()) {
58+
int[] nowPos = q.poll();
59+
int nowY = nowPos[0];
60+
int nowX = nowPos[1];
61+
62+
for(int i=0; i<4; i++) {
63+
int ny = nowY + dy[i];
64+
int nx = nowX + dx[i];
65+
66+
if(ny < 0 || ny >= N || nx < 0 || nx >= N) continue;
67+
if(visited[ny][nx]) continue;
68+
if(isNormal && map[ny][nx] != nowChar) continue;
69+
if(!isNormal) {
70+
if(nowChar == 'B' && map[ny][nx] != 'B') continue;
71+
if(nowChar != 'B' && map[ny][nx] == 'B') continue;
72+
}
73+
q.offer(new int[]{ny, nx});
74+
visited[ny][nx] = true;
75+
}
76+
}
77+
78+
count++;
79+
}
80+
}
81+
82+
return count;
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)