-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOJ2632.cpp
More file actions
112 lines (107 loc) · 3.29 KB
/
POJ2632.cpp
File metadata and controls
112 lines (107 loc) · 3.29 KB
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
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct robotStruct
{
char dir;
int posx, posy;
};
int main(void)
{
const char moveadd[4][2] =
{
0, 1,
1, 0,
0, -1,
-1, 0
};
int K;
int A, B; //Size
int M, N; //N robot M order
cin >> K;
while(K)
{
K--;
cin >> A >> B;
cin >> N >> M;
vector<robotStruct>robot(N);
for(int i = 0; i < N; i++)
{
cin >> robot[i].posx >> robot[i].posy >> robot[i].dir;
switch(robot[i].dir)
{
case 'N':
robot[i].dir = 0;
break;
case 'E':
robot[i].dir = 1;
break;
case 'S':
robot[i].dir = 2;
break;
case 'W':
robot[i].dir = 3;
break;
}
}
char failure[3] = {0, 0, 0};
int sel, repeat;
char order;
for(int i = 0; i < M; i++)
{
cin >> sel >> order >> repeat;
if(failure[0] == 0)
{
switch(order)
{
case 'L':
for( ; repeat > 0; repeat--)
{
if(robot[sel - 1].dir != 0)
robot[sel - 1].dir--;
else
robot[sel - 1].dir = 3;
}
break;
case 'R':
for( ; repeat > 0; repeat--)
{
if(robot[sel - 1].dir != 3)
robot[sel - 1].dir++;
else
robot[sel - 1].dir = 0;
}
break;
case 'F':
for( ; repeat > 0; repeat--)
{
robot[sel - 1].posx += moveadd[robot[sel - 1].dir][0];
robot[sel - 1].posy += moveadd[robot[sel - 1].dir][1];
for(int i = 0; i < N; i++)
if(sel - 1 != i && robot[sel - 1].posx == robot[i].posx && robot[sel - 1].posy == robot[i].posy)
{
failure[0] = 2;
failure[1] = sel - 1;
failure[2] = i;
i = N;
repeat = 0;
}
}
break;
}
if(failure[0] == 0 && (robot[sel - 1].posx < 1 || robot[sel - 1].posx > A || robot[sel - 1].posy < 1 || robot[sel - 1].posy > B))
{
failure[0] = 1;
failure[1] = sel - 1;
}
}
}
if(failure[0] == 0)
cout << "OK" << endl;
else if(failure[0] == 1)
cout << "Robot " << failure[1] + 1 << " crashes into the wall" << endl;
else
cout << "Robot " << failure[1] + 1 << " crashes into robot " << failure[2] + 1 << endl;
}
}