8000 Merge pull request #126 from OceanShape/OS-14503 · windowdong11/basic-algo-lecture@eae07e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit eae07e2

Browse files
Merge pull request encrypted-def#126 from OceanShape/OS-14503
Update 14503.cpp
2 parents 7c37fd1 + 63e8289 commit eae07e2

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

0x0D/solutions/14503.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
2-
// Co-authored by : -
3-
// http://boj.kr/****************
1+
// Authored by : OceanShape
2+
// Co-authored by : BaaaaaaaaaaarkingDog
3+
// http://boj.kr/20cb691fa33b4098908ba7fc390d45a5
44
#include <bits/stdc++.h>
55
using namespace std;
66

7+
int N, M, x, y, d, board[51][51], ans;
8+
int dx[] = {-1, 0, 1, 0};
9+
int dy[] = {0, 1, 0, -1};
10+
711
int main(void){
812
ios::sync_with_stdio(0);
913
cin.tie(0);
10-
11-
}
14+
cin >> N >> M >> x >> y >> d;
15+
for(int i = 0; i < N; ++i)
16+
for(int j = 0; j < M; ++j)
17+
cin >> board[i][j];
18+
int chkCnt = 0; // 방향 탐지 횟수
19+
while(true){
20+
// 청소하지 않은 빈 칸일 경우 청소
21+
if(board[x][y]==0) ++ans;
22+
board[x][y] = -1; // 청소된 칸이라고 표시
23+
bool cleaned = false; // 네 방향 중 청소가 된 곳이 있는지
24+
for(int i = 0; i < 4; i++){
25+
d = (d+3) % 4; // 왼쪽으로 회전
26+
if(board[x+dx[d]][y+dy[d]] == 0){
27+
x += dx[d];
28+
y += dy[d];
29+
cleaned = true;
30+
break;
31+
}
32+
}
33+
if(cleaned) continue;
34+
// 뒤가 벽으로 막혀 있으면, 로봇 청소기 종료
35+
if(board[x-dx[d]][y-dy[d]] == 1)
36+
break;
37+
// 막혀 있지 않을 경우, 후진
38+
x -= dx[d];
39+
y -= dy[d];
40+
}
41+
cout << ans;
42+
}

0 commit comments

Comments
 (0)
0