why?考场代码 30 pts
查看原帖
why?考场代码 30 pts
1001535
封禁用户楼主2024/10/26 15:14
#include <bits/stdc++.h>
using namespace std;
int t;
int n, m, k;
int x, y, d;
char mp[2001][2001];
int ans;
int main() {
	cin >> t;
	while (t--) {
		ans = 0;
		cin >> n >> m >> k;
		cin >> x >> y >> d;
		int nowx = x, nowy = y;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				cin >> mp[i][j];
			}
		}
		while (k > 0) {
			if (d == 0) {
				k--;
				nowx = nowx, nowy = nowy + 1;
				if (nowy > m) {
					d = (d + 1) % 4;
					nowy = nowy - 1;
			//		continue;
				}
				if (mp[nowx][nowy] == '.' && d == 0) {
					ans++;
				}
				if (mp[nowx][nowy] == 'x' && d == 0) {
					d = (d + 1) % 4;
					nowy = nowy - 1;
				}
			}
			if (d == 1) {
				k--;
				nowx = nowx + 1, nowy = nowy;
				if (nowx > n) {
					d = (d + 1) % 4;
					nowx = nowx - 1;
				//	continue;
				}
				if (mp[nowx][nowy] == '.' && d == 1) {
					ans++;
				}
				if (mp[nowx][nowy] == 'x' && d == 1) {
					d = (d + 1) % 4;
					nowx = nowx - 1;
				}
			}
			if (d == 2) {
				k--;
				nowx = nowx, nowy = nowy - 1;
				if (nowy < 1) {
					d = (d + 1) % 4;
					nowy = nowy + 1;
				//	continue;
				}
				if (mp[nowx][nowy] == '.' && d == 2) {
					ans++;
				}
				if (mp[nowx][nowy] == 'x' && d == 2) {
					d = (d + 1) % 4;
					nowy = nowy + 1;
				}
			}
				if (d == 3) {
					k--;
					nowx = nowx - 1, nowy = nowy;
					if (nowx < 1) {
						d = (d + 1) % 4;
						nowx = nowx + 1;
					//	continue;
					}
					if (mp[nowx][nowy] == '.' && d == 3) {
						ans++;
					}
					if (mp[nowx][nowy] == 'x' && d == 3) {
					//	k--;
						d = (d + 1) % 4;
						nowx = nowx + 1;
					}
				}
		}
		cout << ans + 1 << endl;
	}
	return 0;
}
2024/10/26 15:14
加载中...