社区讨论

求神犇帮忙看看

P2360地下城主参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@lo8zi0jd
此快照首次捕获于
2023/10/28 03:06
2 年前
此快照最后确认于
2023/10/28 03:06
2 年前
查看原帖
为什么代码错了
请神犇帮忙看看
CPP
#include<cstdio>
#include<stdio.h>
struct l {
	int chang, kuan, gao,s;
};
l que[30000];
char mp[31][31][31];
bool f[31][31][31];
int main() {
	int chang, kuan, gao;
	int i, j, k,head=1,tail=2,stax,stay,staz;
	scanf("%d%d%d", &gao, &chang, &kuan);
	for (i = 1; gao >= i; i++) {
		for (j = 1; chang >= j; j++) {
			for (k = 1; kuan >= k; k++) {
				scanf("%c", &mp[i][j][k]);
				while(mp[i][j][k] == '\n' || mp[i][j][k] == 0) {
					scanf("%c", &mp[i][j][k]);
				}
				if (mp[i][j][k] == 'S') {
					stax = j;
					stay = k;
					staz = i;
				}
			}
		}
	}
	f[staz][stax][stay]=1;
	que[head].chang = stax;
	que[head].gao = staz;
	que[head].kuan = stay;
	que[head].s = 0;
	bool a = 0;
	int dx[6] = { 0,0,0,0,1,-1 }, dy[6] = { 0,0,1,-1,0,0 }, dz[6] = { 1,-1,0,0,0,0 };
	while (head < tail) {
		if (mp[que[head].gao][que[head].chang][que[head].kuan] == 'E') {
			a = 1;
			break;
		}
		int i;
		for (i = 0; 5 >= i; i++) {
			int tx = que[head].chang+dx[i], ty = que[head].kuan+dy[i], tz = que[head].gao+dz[i];
			if (1 > tx || 1 > ty || 1 > tz || tx > chang || ty > kuan || tz > gao || f[tz][tx][ty]) {
				continue;
			}
			if (mp[tz][tx][ty] == '#') {
				continue;
			}
			f[tz][tx][ty] = 1;
			que[tail].chang = tx;
			que[tail].gao = tz;
			que[tail].kuan = ty;
			que[tail].s = que[head].s + 1;
			tail++;
		}
		head++;
	}
	if (a) {
		printf("Escaped in %d minute(s).", que[head].s);
	}
	else {
		printf("Trapped!");
	}
	return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...