-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path삼성_로봇청소기.cpp
115 lines (107 loc) · 1.91 KB
/
삼성_로봇청소기.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<queue>
#include<cstdio>
using namespace std;
int map[50][50];
bool check[50][50];
int n, m;
struct robot {
int x;
int y;
int r;
int same = 0;
robot(int _x, int _y, int _r) :x(_x), y(_y), r(_r) {}
};
int main() {
scanf("%d %d", &n, &m);
int x, y, r;
scanf("%d %d %d", &y, &x, &r);
robot first(x, y, r);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
scanf("%d", &map[i][j]);
int cnt = 0;
queue<robot> q;
q.push(first);
while (!q.empty()) {
robot now = q.front();
q.pop();
if (!check[now.y][now.x]) {
check[now.y][now.x] = true;
cnt++;
}
if (now.same == 4) {
if (now.r == 0) {
if (map[now.y + 1][now.x] == 0)
{
now.y += 1;
now.same = 0;
q.push(now);
}
}
else if (now.r == 1) {
if (map[now.y][now.x - 1] == 0) {
now.x -= 1;
now.same = 0;
q.push(now);
}
}
else if (now.r == 2) {
if (map[now.y - 1][now.x] == 0) {
now.y -= 1;
now.same = 0;
q.push(now);
}
}
else if (now.r == 3) {
if (map[now.y][now.x + 1] == 0) {
now.x += 1;
now.same = 0;
q.push(now);
}
}
}
else {
if (now.r == 0) {
if (!check[now.y][now.x - 1] && map[now.y][now.x-1] == 0) {
now.same = 0;
now.x -= 1;
}
else
now.same++;
now.r = 3;
q.push(now);
}
else if (now.r == 1) {
if (!check[now.y-1][now.x] && map[now.y - 1][now.x] == 0) {
now.same = 0;
now.y -= 1;
}
else
now.same++;
now.r = 0;
q.push(now);
}
else if (now.r == 2) {
if (!check[now.y][now.x+1] && map[now.y][now.x + 1] == 0) {
now.same = 0;
now.x += 1;
}
else
now.same++;
now.r = 1;
q.push(now);
}
else if (now.r == 3) {
if (!check[now.y + 1][now.x] && map[now.y + 1][now.x] == 0) {
now.same = 0;
now.y += 1;
}
else
now.same++;
now.r = 2;
q.push(now);
}
}
}
printf("%d\n", cnt);
}