Skip to content

Commit a1203f8

Browse files
authored
Merge pull request #519 from AlgorithmWithGod/0224LJH
[20250721] BOJ / G3 / 소문난 칠공주 / 이종환
2 parents 43e8267 + 6b5b877 commit a1203f8

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
```java
2+
import java.awt.*;
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.HashSet;
7+
import java.util.Set;
8+
9+
10+
public class Main {
11+
static String[][] arr = new String[5][5];
12+
static Set<Point> set = new HashSet<>();
13+
static HashSet<Point> temp = new HashSet<>();
14+
static int[] dy = { -1,0,1,0};
15+
static int[] dx = { 0,1,0,-1};
16+
static int ans = 0;
17+
18+
19+
public static void main(String[] args) throws IOException {
20+
init();
21+
process();
22+
print();
23+
}
24+
25+
private static void init() throws IOException {
26+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
27+
for (int i = 0; i < 5; i++) {
28+
arr[i] = br.readLine().split("");
29+
}
30+
}
31+
32+
private static void process() throws IOException {
33+
combination(0,0);
34+
}
35+
36+
private static void combination(int num, int idx) {
37+
if ( idx == 7) {
38+
check();
39+
return;
40+
}
41+
42+
for (int i = num; i < 25; i++){
43+
int y = i/5;
44+
int x = i%5;
45+
46+
set.add(new Point(x, y));
47+
combination(i+1, idx+1);
48+
set.remove(new Point(x, y));
49+
}
50+
}
51+
52+
private static void check() {
53+
54+
55+
Point first = set.iterator().next();
56+
57+
int sCount = 0;
58+
for (Point p : set) {
59+
if(arr[p.y][p.x].equals("S") ) sCount++;
60+
}
61+
62+
63+
if (sCount >= 4 && checkConnected(first)) {
64+
ans++;
65+
}
66+
67+
}
68+
69+
private static boolean checkConnected(Point first) {
70+
temp = new HashSet<>();
71+
temp.add(first);
72+
73+
for (int i = 0 ; i < 7; i++){
74+
for (Point p : set) {
75+
if (temp.contains(p)) continue;
76+
77+
boolean isConnected = false;
78+
for (int j = 0; j <4 ; j++){
79+
int ny = p.y + dy[j];
80+
int nx = p.x + dx[j];
81+
82+
if (temp.contains(new Point(nx, ny))) {
83+
isConnected = true;
84+
break;
85+
}
86+
}
87+
88+
if (isConnected) {
89+
temp.add(p);
90+
}
91+
}
92+
}
93+
94+
return temp.size() == 7;
95+
96+
}
97+
98+
99+
private static void print() {
100+
System.out.println(ans);
101+
}
102+
103+
104+
105+
}
106+
107+
```

0 commit comments

Comments
 (0)