题解
2025-07-05 19:54:31
发布于:浙江
2阅读
0回复
0点赞
#include <iostream>
#include <vector>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
vector<vector<int>> grid(m, vector<int>(n));
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
cin >> grid[i][j];
}
}
int x, y, k;
char s;
cin >> x >> y >> s >> k;
vector<pair<int, int>> dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int direction;
if (s == 'U') direction = 0;
else if (s == 'R') direction = 1;
else if (s == 'D') direction = 2;
else direction = 3;
for (int step = 0; step < k; ++step) {
int currentColor = grid[x][y];
if (currentColor == 1) {
direction = (direction + 1) % 4;
grid[x][y] = 0;
} else {
direction = (direction + 3) % 4;
grid[x][y] = 1;
}
x += dirs[direction].first;
y += dirs[direction].second;
}
cout << x << " " << y << endl;
return 0;
}
这里空空如也
有帮助,赞一个