既MLE又TLE求调
查看原帖
既MLE又TLE求调
785810
wyyybb楼主2024/10/7 15:10
#include <bits/stdc++.h>
using namespace std;
int Mmap[166][166], n, m, Mmove[8][2] = {1, 2, 1, -2, -1, 2, -1, -2, 2, 1, 2, -1, -2, 1, -2, -1}, pos1, pos2, cnt = 0,num;
char c;
int main(void) {
	memset(Mmap, 10, sizeof(Mmap));
	queue<pair<pair<int, int>, int> > q;
	cin >>  n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> c;
			if (c == '.') Mmap[i][j] = 0;
			if (c == '*') Mmap[i][j] = 1;
			if (c == 'K') {
				q.push(make_pair(make_pair(i, j), 0));
			}
			if (c == 'H') Mmap[i][j] = 2;
		}
	}

	while (!q.empty()) {
		pos1 = q.front().first.first;
		pos2 = q.front().first.second;
		num = q.front().second;
		Mmap[pos1][pos2] = 1;
		cnt++;
		if (Mmap[pos1][pos2] == 2) {
			cout << cnt;
			exit(0);
		}
		for (int i = 0; i < 8; i++) {
			if (Mmap[pos1 + Mmove[i][0]][pos2 + Mmove[i][1]] ==  0) {
				q.push(make_pair(make_pair(pos1 + Mmove[i][0], pos2 + Mmove[i][1]), num + 1));
				Mmap[pos1][pos2] = 1;
			} else continue;
		}
	}
	exit(0);
}

内存消耗疑似无穷大,调试把我电脑都给弄死机(最后强制重启)了,还是死循环。

什么自动死机器

2024/10/7 15:10
加载中...