Help!!!
查看原帖
Help!!!
1124480
t202482楼主2023/11/17 16:12

样例都没过……

#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
#define INF 2139062143
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
struct point{int x, y;};
int main() {
	int m, a[305][305], cnt[305][305]={}, d[]={0,1,-1}, x, y, t; cin >> m, memset(a, 127, sizeof(a));
	for(int i=0; i<m; ++i) {
		cin >> x >> y >> t, a[x][y] = min(a[x][y], t),
		a[x][y+1] = min(a[x][y+1], t), a[x+1][y] = min(a[x+1][y], t);
		if(y) a[x][y-1] = min(a[x][y-1], t); if(x) a[x-1][y] = min(a[x-1][y], t);
	}
	queue<point>q; point p1, p2; p1.x=p1.y=0, q.push(p1);
	for(; !q.empty();) {
		p1=q.front(), q.pop(); cout<<p1.x<<' '<<p1.y<<'\n';
		if(a[p1.x][p1.y]==INF) {cout<<cnt[p1.x][p1.y]; return 0;}
		for(int i=0; i<3; ++i) {
			for(int j=0; j<3; ++j) {
				if(d[i]+d[j]&&d[i]^d[j]) {
					if(p1.x+d[i]>=0&&p1.y+d[j]>=0&&(!cnt[p1.x+d[i]][p1.y+d[j]]))
						p2.x=p1.x+d[i], p2.y=p1.y+d[j], cnt[p2.x][p2.y]=cnt[p1.x][p1.y]+1, q.push(p2);
				}
			}
		}
	}
	cout << -1; return 0;
}
2023/11/17 16:12
加载中...