Skip to content

Commit 285198b

Browse files
committed
Lv2_거리두기확인하기
1 parent b810dc6 commit 285198b

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
#include <queue>
5+
using namespace std;
6+
7+
struct node {
8+
int y;
9+
int x;
10+
int count;
11+
};
12+
13+
int dx[] = { 0,1,0,-1 };
14+
int dy[] = { 1,0,-1,0 };
15+
16+
bool check(int y, int x, int i, vector<vector<string>> &places) {
17+
queue<node> q;
18+
q.push({ y,x,0 });
19+
20+
vector<vector<bool>> visited(5, vector<bool>(5, false));
21+
visited[y][x] = true;
22+
23+
while (!q.empty()) {
24+
int y = q.front().y;
25+
int x = q.front().x;
26+
int count = q.front().count;
27+
q.pop();
28+
29+
if (count == 2)
30+
continue;
31+
32+
for (int k = 0; k < 4; ++k) {
33+
int ny = y + dy[k];
34+
int nx = x + dx[k];
35+
36+
if (ny < 0 || ny >4 || nx < 0 || nx>4 || visited[ny][nx])
37+
continue;
38+
if (places[i][ny][nx] == 'X')
39+
continue;
40+
if (places[i][ny][nx] == 'P' && count <= 1)
41+
return false;
42+
visited[ny][nx] = true;
43+
q.push({ ny,nx,count + 1 });
44+
}
45+
}
46+
47+
return true;
48+
}
49+
50+
vector<int> solution(vector<vector<string>> places) {
51+
vector<int> answer;
52+
53+
for (int i = 0; i < 5; ++i) {
54+
bool flag = false;
55+
for (int j = 0; j < 5; ++j) {
56+
flag = false;
57+
for (int k = 0; k < 5; ++k) {
58+
if (places[i][j][k] == 'P') {
59+
if (!check(j, k, i,places)) {
60+
flag = true;
61+
break;
62+
}
63+
}
64+
}
65+
if (flag)
66+
break;
67+
}
68+
69+
if (flag)
70+
answer.push_back(0);
71+
else
72+
answer.push_back(1);
73+
}
74+
75+
return answer;
76+
}
77+
78+
int main() {
79+
vector<vector<string>> places = {{"POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"}, {"POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"}, {"PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"}, {"OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"}, {"PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"}};
80+
vector<int> ans = solution(places);
81+
82+
for (auto a : ans)
83+
cout << a << " ";
84+
85+
return 0;
86+
}

Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@
196196
<ClCompile Include="Lv2\Lv2_가장큰정사각형찾기.cpp">
197197
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
198198
</ClCompile>
199+
<ClCompile Include="Lv2\Lv2_거리두기확인하기.cpp">
200+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
201+
</ClCompile>
199202
<ClCompile Include="Lv2\Lv2_괄호변환.cpp">
200203
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
201204
</ClCompile>

Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,5 +531,8 @@
531531
<ClCompile Include="Lv2\Lv2_뉴스클러스터링.cpp">
532532
<Filter>소스 파일</Filter>
533533
</ClCompile>
534+
<ClCompile Include="Lv2\Lv2_거리두기확인하기.cpp">
535+
<Filter>소스 파일</Filter>
536+
</ClCompile>
534537
</ItemGroup>
535538
</Project>

0 commit comments

Comments
 (0)