#include<iostream>
using namespace std;
const int MAX = 51;
int n, m;
pair<pair<int, int>, int> currentpos;
int way[MAX][MAX];
typedef struct {
int x, y;
}Move;
Move mv[4] = { {-1,0}, {0,1}, {1,0}, {0,-1} };
int calclean() {
int ans = 0;
while (true) {
if (way[currentpos.first.first][currentpos.first.second] == 0) {
ans++;
way[currentpos.first.first][currentpos.first.second] = 2;
}
int flag = 0;
for (int i = 0; i < 4; i++) {
currentpos.second--;
if (currentpos.second == -1)
currentpos.second = 3;
int x = currentpos.first.first + mv[currentpos.second].x;
int y = currentpos.first.second + mv[currentpos.second].y;
if (way[x][y] == 0) {
currentpos.first.first = x;
currentpos.first.second = y;
flag = 1;
break;
}
}
if (flag == 1)
continue;
int dir = currentpos.second - 2;
if (dir == -1)
dir = 3;
if (dir== -2)
dir = 2;
currentpos.first.first += mv[dir].x;
currentpos.first.second += mv[dir].y;
if (way[currentpos.first.first][currentpos.first.second] == 1)
break;
}
return ans;
}
int main(void) {
cin >> n >> m;
cin >> currentpos.first.first >> currentpos.first.second >> currentpos.second;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> way[i][j];
}
}
cout << calclean();
}
'백준 알고리즘 > 시뮬레이션' 카테고리의 다른 글
백준 3190번 C++ (0) | 2019.01.29 |
---|---|
백준 14499번 C++ (0) | 2019.01.27 |
백준 1547 파이썬 (0) | 2018.11.13 |
백준 10219 파이썬 (0) | 2018.11.12 |
백준 1057 파이썬 (0) | 2018.11.06 |