下载的数据吻合但是RE,求教!!!
查看原帖
下载的数据吻合但是RE,求教!!!
1491219
user_888楼主2025/2/8 17:46
#include <iostream>
using namespace std;
#include<queue>
#include<cstring>
pair<int, int> pos[4] = { {1,0},{0,1},{0,-1},{-1,0} };
int cao[305][305], death[305][305];
int m,x,y,t;

int main(){
	memset(death, 0x7f,sizeof(death));
	cin >> m;
	for (int i = 0;i < m;i++) {
		cin >> x >> y >> t;
		death[x][y] = min(death[x][y], t);
		for (int j = 0;j <= 3;j++) {
			int ix = x + pos[j].first, iy = y + pos[j].second;
			if (ix>=0  && iy>=0 ) {
				death[ix][iy] = min(death[ix][iy], t);
			}
		}
	}
	memset(cao, -1, sizeof(cao));
	queue<pair<int, int>>q;
	q.push({ 0,0 });
	cao[0][0] = 0;
	while (!q.empty()) {
		int x = q.front().first, y = q.front().second;
		q.pop();
		for (int i = 0;i < 4;i++) {
			int ix = x+pos[i].first, iy = y+pos[i].second;
			if (ix < 0 || iy < 0 || cao[ix][iy] != -1 || cao[x][y]+1 >= death[ix][iy]) {
				continue;
			}
			q.push({ ix,iy });
			cao[ix][iy] = cao[x][y]+1;
		}
	}
	int res = 1000000000;
	for (int i = 0;i < 305;i++) {
		for (int j = 0;j < 305;j++) {
			if (death[i][j] == 2139062143 && cao[i][j] != -1) {
				res = min(res, cao[i][j]);
			}
		}
	}
	if (res == 1000000000)cout << -1;
	else cout << res;
	return 0;
}

RE了1,3,6,7,8,9,10,11,12,13,14数据点, 于是下载了数据点1的数据,调试界面如下:

4
0 0 2
2 1 2
1 1 2
0 3 5
5请按任意键继续. . .

也输出了正确答案,为什么RE,求教

2025/2/8 17:46
加载中...