-
Notifications
You must be signed in to change notification settings - Fork 0
/
Angel_and_Devils.cpp
177 lines (133 loc) · 3.77 KB
/
Angel_and_Devils.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define ii pair<int, int>
void solve(ii angel, string dev, vector<ii> dev_pos) {
int mat[13][13];
memset(mat, 0, sizeof(mat));
int x = angel.ff, y= angel.ss;
int xi_r, xi_c, og_r, og_c, ze_r, ze_c;
for(int i=0; i<3; i++) {
if(dev[i]=='X') xi_r = dev_pos[i].ff, xi_c = dev_pos[i].ss;
if(dev[i]=='O') og_r = dev_pos[i].ff, og_c = dev_pos[i].ss;
if(dev[i]=='Z') ze_r = dev_pos[i].ff, ze_c = dev_pos[i].ss;
}
// ZeeSnake mov direction
bool flag = true, down = true, right = true;
// movement direction for Angel
char move;
if(x==1) move='d';
else if(x==12) move='u';
else if(y==1) move='r';
else move='l';
for(int i=1; i<=12; i++) {
// mark as visited
mat[ze_r][ze_c] = -1;
// cout<<i<<endl;
// cout<<move<<endl;
// cout<<"x:"<<x<<" "<<"y:"<<y<<endl;
// cout<<"og_r:"<<og_r<<" "<<"og_c:"<<og_c<<endl;
// cout<<"xi_r:"<<xi_r<<" "<<"xi_c:"<<xi_c<<endl;
// cout<<"ze_r:"<<ze_r<<" "<<"ze_c:"<<ze_c<<endl;
// For ZeeSnake
if(mat[x][y]==-1) {
char ch = 'A'+y-1;
cout<<ch<<x<<endl;
return;
}
// moving ZeeSnake
if(flag) {
// down/up
if(ze_r==12) down = false;
if(ze_r==1) down = true;
if(down) ze_r++;
else ze_r--;
flag = false;
}
else {
// right/left
if(ze_c==12) right = false;
if(ze_c==1) right = true;
if(right) ze_c++;
else ze_c--;
flag = true;
}
// For xixi
if(((xi_r%2==xi_c%2) == (x%2==y%2)) && i==xi_r) {
char ch = 'A'+y-1;
cout<<ch<<x<<endl;
return;
}
// For Ogre
if(i==2) {
bool kill = false;
if(og_r+1==x && og_c==y) kill = true;
else if(og_r-1==x && og_c==y) kill = true;
else if(og_r==x && og_c+1==y) kill = true;
else if(og_r==x && og_c-1==y) kill = true;
else if(og_r-1==x && og_c-1==y) kill = true;
else if(og_r+1==x && og_c+1==y) kill = true;
else if(og_r+1==x && og_c-1==y) kill = true;
else if(og_r-1==x && og_c+1==y) kill = true;
if(kill) {
char ch = 'A'+y-1;
cout<<ch<<x<<endl;
return;
}
}
else if(i==3 && og_r==x && og_c==y) {
char ch = 'A'+y-1;
cout<<ch<<x<<endl;
return;
}
// movement direction of Angel
if(move=='d') x++;
if(move=='u') x--;
if(move=='r') y++;
if(move=='l') y--;
}
cout<<"SS"<<endl;
return;
}
ii get_pos(string s) {
ii p;
// K12
p.ss = s[0] - 65 +1;
if(s.size()>2) p.ff = (s[1] - 48)*10 + (s[2]-48);
else p.ff = s[1] - 48;
return p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
// Get angel position
cin>>s;
// pair<row, col>
ii angel = get_pos(s);
//cout<<angel.ff<<" "<<angel.ss<<endl;
// Get devils
string devils;
cin>>s;
for(int i=0; i<s.size(); i++) if(s[i]!=',') devils.push_back(s[i]);
//cout<<devils<<endl;
// Get devils position
vector<ii> dev_pos;
string t="";
cin>>s;
s += ",";
for(int i=0; i<s.size(); i++) {
if(s[i]!=',') t.push_back(s[i]);
else {
dev_pos.push_back(get_pos(t));
t = "";
}
}
// for(int i=0; i<3; i++) {
// cout<<dev_pos[i].ff<<" "<<dev_pos[i].ss<<endl;
// }
solve(angel, devils, dev_pos);
}
//