Skip to content

Commit eed5c76

Browse files
committed
53주차
1 parent 158fa38 commit eed5c76

File tree

11 files changed

+670
-33
lines changed

11 files changed

+670
-33
lines changed

src/main/java/org/example/_52week/Test.java

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.example._54week;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
public class BreadStore {
9+
10+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
12+
private static boolean found = false;
13+
private static int answer = 0;
14+
private static int R;
15+
private static int C;
16+
private static boolean[][] map;
17+
18+
private static final boolean EMPTY = false;
19+
private static final boolean BUILDING = true;
20+
21+
private static final int[][] dir = {{-1, 1}, {0, 1}, {1, 1}};
22+
23+
public static void main(String[] args) throws IOException {
24+
StringTokenizer st = new StringTokenizer(br.readLine());
25+
R = Integer.parseInt(st.nextToken());
26+
C = Integer.parseInt(st.nextToken());
27+
map = new boolean[R][C];
28+
29+
for (int row = 0; row < R; row++) {
30+
String input = br.readLine();
31+
32+
for (int col = 0; col < C; col++) {
33+
map[row][col] = input.charAt(col) == '.' ? EMPTY : BUILDING;
34+
}
35+
}
36+
37+
for (int row = 0; row < R; row++) {
38+
if (map[row][0] == BUILDING) {
39+
continue;
40+
}
41+
42+
dfs(row, 0);
43+
found = false;
44+
}
45+
46+
System.out.println(answer);
47+
}
48+
49+
private static void dfs(int row, int col) {
50+
if (col == C - 1) {
51+
answer++;
52+
53+
found = true;
54+
return;
55+
}
56+
57+
for (int i = 0; i < 3; i++) {
58+
int nextRow = row + dir[i][0];
59+
int nextCol = col + dir[i][1];
60+
61+
if (nextRow < 0 || nextRow >= R || nextCol < 0 || nextCol >= C) {
62+
continue;
63+
}
64+
65+
if (map[nextRow][nextCol] == BUILDING) {
66+
continue;
67+
}
68+
69+
map[nextRow][nextCol] = BUILDING;
70+
dfs(nextRow, nextCol);
71+
if (found) {
72+
return;
73+
}
74+
}
75+
}
76+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
//package org.example._54week;
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.PriorityQueue;
8+
//import java.util.Queue;
9+
//import java.util.StringTokenizer;
10+
//
11+
//public class CastleDefense {
12+
//
13+
// private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
//
15+
// private static int answer = 0;
16+
// private static int[][] map;
17+
// private static int rowSize;
18+
// private static int colSize;
19+
// private static int distance;
20+
//
21+
// public static void main(String[] args) throws IOException {
22+
// StringTokenizer st = new StringTokenizer(br.readLine());
23+
//
24+
// rowSize = Integer.parseInt(st.nextToken());
25+
// colSize = Integer.parseInt(st.nextToken());
26+
// distance = Integer.parseInt(st.nextToken());
27+
//
28+
// map = new int[rowSize + 1][colSize];
29+
// for (int i = 0; i < rowSize; i++) {
30+
// StringTokenizer input = new StringTokenizer(br.readLine());
31+
//
32+
// for (int j = 0; j < colSize; j++) {
33+
// map[i][j] = Integer.parseInt(input.nextToken());
34+
// }
35+
// }
36+
//
37+
// colSize = 5;
38+
//
39+
// // 조합 구하기
40+
// boolean[] archers = new boolean[colSize];
41+
// backtracking(0, 0, archers);
42+
// }
43+
//
44+
// private static void backtracking(int depth, int selectedCnt, boolean[] archers) {
45+
// if (selectedCnt >= 4) {
46+
// return;
47+
// }
48+
//
49+
// if (selectedCnt == 3) {
50+
// printArchers(archers);
51+
// int cnt = calculate(archers);
52+
// answer = Math.max(answer, cnt);
53+
// return;
54+
// }
55+
//
56+
// for (int i = depth; i < colSize; i++) {
57+
// archers[i] = true;
58+
// backtracking(i + 1, selectedCnt + 1, archers);
59+
// archers[i] = false;
60+
// }
61+
// }
62+
//
63+
// private static int calculate(boolean[] archers) {
64+
// int[] archerCol = new int[3];
65+
//
66+
// for (int i = 0, idx = 0; i < archers.length; i++) {
67+
// if (archers[i]) {
68+
// archerCol[idx++] = i;
69+
// }
70+
// }
71+
//
72+
// int[][] newMap = copyArray(map);
73+
// boolean[][] dead = new boolean[rowSize][colSize];
74+
////
75+
//// PriorityQueue<int[]>[] queues = new PriorityQueue<>[3];
76+
//// for (int i = 0; i < 3; i++) {
77+
//// int col = archerCol[i];
78+
//// queues[i] = new PriorityQueue<>((e1, e2) -> {
79+
//// int distance1 = Math.abs(rowSize - e1[0]) + Math.abs(col - e1[0]);
80+
//// int distance2 = Math.abs(rowSize - e2[0]) + Math.abs(col - e2[0]);
81+
////
82+
//// return Integer.compare(distance1, distance2);
83+
//// });
84+
//// }
85+
////
86+
//// for (int row = 0; row < rowSize; row++) {
87+
//// for (int col = 0; col < colSize; col++) {
88+
//// if (map[row][col] == 1) {
89+
//// queues[0].add(new int[]{row, col, 0});
90+
//// queues[1].add(new int[]{row, col, 1});
91+
//// queues[2].add(new int[]{row, col, 2});
92+
//// }
93+
//// }
94+
//// }
95+
////
96+
//// for (int i = rowSize + 1; i >= 0; i--) {
97+
//// int[] cell1 = null;
98+
//// while (!queues[0].isEmpty()) {
99+
//// cell1 = queues[0].peek();
100+
//// if (cell1[0] <= i) {
101+
//// break;
102+
//// } else {
103+
//// cell1 = null;
104+
//// }
105+
//// }
106+
////
107+
//// int[] cell2 = null;
108+
//// while (!queues[1].isEmpty()) {
109+
//// cell1 = queues[0].peek();
110+
//// if (cell1[0] <= i) {
111+
//// break;
112+
//// } else {
113+
//// cell1 = null;
114+
//// }
115+
//// }
116+
////
117+
//// int[] cell3 = null;
118+
//// while (!queues[2].isEmpty()) {
119+
//// cell1 = queues[0].peek();
120+
//// if (cell1[0] <= i) {
121+
//// break;
122+
//// } else {
123+
//// cell1 = null;
124+
//// }
125+
//// }
126+
////
127+
////
128+
////
129+
// }
130+
//
131+
// return 0;
132+
// }
133+
//
134+
// private static void printArchers(boolean[] archers) {
135+
// for (int i = 0; i < archers.length; i++) {
136+
// System.out.print(archers[i] ? "O" : "X");
137+
// }
138+
// System.out.println();
139+
// }
140+
//
141+
// private static int[][] copyArray(int[][] map) {
142+
// int[][] newMap = new int[rowSize][colSize];
143+
//
144+
// for (int row = 0; row < rowSize; row++) {
145+
// for (int col = 0; col < colSize; col++) {
146+
// newMap[row][col] = map[row][col];
147+
// }
148+
// }
149+
//
150+
// return newMap;
151+
// }
152+
//}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.example._54week;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Concurrent {
7+
8+
public static void main(String[] args) {
9+
List<String> arr = new ArrayList<>();
10+
11+
arr.add("A");
12+
arr.add("B");
13+
arr.add("C");
14+
arr.add("D");
15+
arr.add("E");
16+
arr.add("F");
17+
18+
for (String value : arr) {
19+
if (value.equals("C")) {
20+
arr.remove("C");
21+
}
22+
}
23+
}
24+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package org.example._54week;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
public class FlipCoin {
8+
9+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
private static int N;
11+
private static boolean[][] map;
12+
13+
private static final boolean FRONT = true;
14+
private static final boolean BACK = false;
15+
private static int answer = Integer.MAX_VALUE;
16+
17+
public static void main(String[] args) throws IOException {
18+
N = Integer.parseInt(br.readLine());
19+
map = new boolean[N][N];
20+
21+
for (int i = 0; i < N; i++) {
22+
String row = br.readLine();
23+
24+
for (int j = 0; j < N; j++) {
25+
map[i][j] = row.charAt(j) == 'H' ? FRONT : BACK;
26+
}
27+
}
28+
29+
permutation(0, new boolean[N]);
30+
System.out.println(answer);
31+
}
32+
33+
private static void permutation(int depth, boolean[] mask) {
34+
if (depth == N) {
35+
int[] backCnt = new int[N];
36+
for (int row = 0; row < N; row++) {
37+
for (int col = 0; col < N; col++) {
38+
if ((mask[row] && map[row][col]==FRONT) || (!mask[row] && map[row][col] == BACK)) {
39+
backCnt[col]++;
40+
}
41+
}
42+
}
43+
44+
int sum = 0;
45+
for (int i = 0; i < N; i++) {
46+
sum += Math.min(backCnt[i], N - backCnt[i]);
47+
}
48+
49+
answer = Math.min(answer, sum);
50+
return;
51+
}
52+
53+
mask[depth] = true;
54+
permutation(depth + 1, mask);
55+
mask[depth] = false;
56+
permutation(depth + 1, mask);
57+
}
58+
59+
private static void printArray(boolean[][] newMap) {
60+
for (int row = 0; row < N; row++) {
61+
for (int col = 0; col < N; col++) {
62+
System.out.print(newMap[row][col] == FRONT ? "H" : "T");
63+
}
64+
System.out.println();
65+
}
66+
System.out.println();
67+
}
68+
69+
private static void printMask(boolean[] mask) {
70+
StringBuilder sb = new StringBuilder();
71+
for (int i = 0; i < N; i++) {
72+
sb.append(mask[i] ? "1" : "0");
73+
}
74+
75+
System.out.println(sb);
76+
}
77+
78+
private static boolean[][] copyArray(boolean[][] map) {
79+
boolean[][] newMap = new boolean[N][N];
80+
for (int row = 0; row < N; row++) {
81+
for (int col = 0; col < N; col++) {
82+
newMap[row][col] = map[row][col];
83+
}
84+
}
85+
86+
return newMap;
87+
}
88+
}

0 commit comments

Comments
 (0)