题目链接:
PREV-33 兰顿蚂蚁
思路:
按照题意模拟即可
代码:
#include<bits/stdc++.h>
using namespace std;
bool a[105][105];
int m, n, x, y, s, k;
int mx[4] = {-1, 0, 1, 0}, my[4] = {0, 1, 0, -1};
inline void move() {
if(a[x][y]) s = (s + 1) % 4;
else s = (s + 3) % 4;
a[x][y] = !a[x][y], x += mx[s], y += my[s];
}
int main() {
#ifdef MyTest
freopen("Sakura.txt", "r", stdin);
#endif
cin >> m >> n;
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) cin >> a[i][j];
}
scanf("%d %d %c %d", &x, &y, &s, &k);
if(s == 'U') s = 0;
else if(s == 'R') s = 1;
else if(s == 'D') s = 2;
else s = 3;
while(k--) move();
cout << x << ' ' << y;
return 0;
}