Japan Registry Services (JPRS) Programming Contest 2024 (AtCoder Beginner Contest 339)
B - Langton’s Takahashib题目大意:给定一个人,如果在.变成#然后顺时针旋转,如果在.变成#然后逆时针。 解法:开一个数组模拟顺时针运动。用一个变量d来确定位置。然后需要取余来防止越界
#include<bits/stdc++.h>
using namespace std;
#define i64 long long
const int MAXN = 1010;
char a[MAXN][MAXN];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int x = 0, y = 0, d = 0;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int H, W, N;
cin >> H >> W >> N;
for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j ++) {
a[i][j] = '.';
}
}
while(N--) {
if(a[x][y] == '.') {
a[x][y] = '#';
d = (d + 1) % 4;
} else {
a[x][y] = '.';
d = (d + 3) % 4;
}
x = (x + dx[d] + H) % H;
y = (y + dy[d] + W) % W;
}
for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j ++) {
cout << a[i][j];
}
cout << "\n";
}
return 0;
}