为啥50分啊啊啊!!!求助!
查看原帖
为啥50分啊啊啊!!!求助!
1423361
ljz_Math楼主2024/10/26 22:31
#include<iostream>
using namespace std;
int main() {
	int T;//数据组数
	int n, m, k;//行数,列数,执行次数
	int x0, y0, d0;//起始横坐标,起始纵坐标,起始朝向
	char c[10000][10000] = { '0' };
	cin >> T;
	int sum[10000];
	int key[10000][10000] = { 0 };
	for (int i = 1; i <= T; i++) {
		sum[i] = 1;
	}
	for (int s = 1; s <= T; s++) {
		
		cin >> n >> m >> k;
		cin >> x0 >> y0 >> d0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				key[i][j] = 0;
			}
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				cin >> c[i][j];//输入地图
			}
		}
		for (int i = 1; i <= n; i++) {
			c[i][0] = '0';
			c[i][m + 1] = '0';
		}
		for (int j = 1; j <= m; j++) {
			c[0][j] = '0';
			c[n + 1][j] = '0';
		}
		//cout << c[1][0];
		//cout << endl;
		//cout << d0;
		for (int i = 1; i <= k; i++) {
			if (d0 == 0) {
				if (c[x0][y0 + 1] == '0' || c[x0][y0 + 1] == 'x') {
					d0 = (d0 + 1) % 4;
					//cout << "q1" << endl;
				}
				else {
					if (key[x0][y0+1] == 1) {
						sum[s] = sum[s];
					}
					else {
						sum[s]++;
						key[x0][y0+1] = 1;
						//cout << "R0"<<endl;
					}
					y0++;
				}
			}
			else if (d0 == 1) {
				if (c[x0 + 1][y0] == '0' || c[x0 + 1][y0] == 'x') {
					d0 = (d0 + 1) % 4;
					//cout << "q1" << endl;
				}
				else {
					if (key[x0+1][y0] == 1) {
						sum[s] = sum[s];
					}
					else {
						sum[s]++;
						key[x0+1][y0] = 1;
						//cout << "R1" << endl;
					}
					x0++;
				}
			}
			else if (d0 == 2) {
				if (c[x0][y0 - 1] == '0' || c[x0][y0 - 1] == 'x') {
					d0 = (d0 + 1) % 4;
					//cout << "q1" << endl;
					//cout << d0 << endl;
				}
				else {
					if (key[x0][y0-1] == 1) {
						sum[s] = sum[s];
					}
					else {
						sum[s]++;
						key[x0][y0-1] = 1;
						//cout << "R2" << endl;
					}
					y0--;
				}
			}
			else if (d0 == 3) {
				if (c[x0 - 1][y0] == '0' || c[x0 - 1][y0] == 'x') {
					d0 = (d0 + 1) % 4;
					//cout << "q1" << endl;
				}
				else {
					if (key[x0-1][y0] == 1) {
						sum[s] = sum[s];
					}
					else {
						sum[s]++;
						key[x0-1][y0] = 1;
						//cout << "R3" << endl;
					}
					x0--;
				}
			}
		}
	}
	for (int i = 1; i <= T; i++) {
		cout << sum[i] << endl;
	}
	return 0;
}
2024/10/26 22:31
加载中...