求调P2895
  • 板块学术版
  • 楼主Leeqyx
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/19 21:41
  • 上次更新2024/10/19 23:38:50
查看原帖
求调P2895
1029916
Leeqyx楼主2024/10/19 21:41

链接

#include<bits/stdc++.h>
using namespace std;

short m,x,y,t;
struct Pp{
	int x,y,t;
	Pp(){};
	Pp(int xx,int yy,int tt){x = xx;y = yy;t = tt;};
};
short mp[310][310];
int dx[5] = {0,1,0,-1,0},dy[5] = {0,0,1,0,-1};
queue<Pp> q;

signed main() {
//	ios::sync_with_stdio(0);
//	cin.tie(0);
//	cout.tie(0);

	cin>>m;
	q.push(Pp(0,0,0));
	for(int i = 0; i <= 310; i++)
		for(int j = 0; j <= 310; j++)
			mp[i][j] = -1;
	for(int i = 1; i <= m; i++) {
		cin>>x>>y>>t;
		for(int j = 0; j <= 4; j++)
			if(x + dx[j] >= 0 and y + dy[j] >= 0)
				mp[x + dx[j]][y + dy[j]] = mp[x + dx[j]][y + dy[j]] == -1?t:min(t,mp[x + dx[j]][y + dy[j]]);
	}cout<<1<<q.size()<<'\n';
//	for(int i = 0; i <= 10; i++,cout<<'\n')
//		for(int j = 0; j <= 10; j++)
//			cout<<mp[P(i,j)]<<' ';
//	q.push(Pp(0,0,0));

	while(!q.empty()) {	
		Pp point = q.front();
//		cout<<1<<'\n';
		q.pop();
		x = point.x,y = point.y,t = point.t + 1;
		for(int i = 1; i <= 4; i++) {
			if(x + dx[i] >= 0 and y + dy[i] >= 0)
				if(mp[x + dx[i]][y + dy[i]] == -1) {
					cout<<t;
					return 0;
				} else if(mp[x + dx[i]][y + dy[i]] > t)
					q.push(Pp(x + dx[i],y + dy[i],t));
		}
	}
	cout<<-1;
}
2024/10/19 21:41
加载中...