标签:str com get out bsp ring namespace include problem
链接:Miku
----------------
这题没边界,用bfs比较好
与处理完了就没什么好说的特别之处
------------------
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; int safe[305][305]; int t[305][305]; int m; int mx[5]={1,-1,0,0}; int my[5]={0,0,1,-1}; int xi,yi,ti; struct b{ int x; int y; int tim; }; int vis[305][305]; queue <b> q; int f; b l; void bfs(){ while(q.size()){ int nx=q.front().x; int ny=q.front().y; int nt=q.front().tim; vis[nx][ny]=1; q.pop(); if(!safe[nx][ny]){ cout<<nt; return ; } for(int i=0;i<=3;++i){ int vx=nx+mx[i]; int vy=ny+my[i]; if(vx>=0&&vy>=0) if(nt+1<t[vx][vy]) { if(!vis[vx][vy]) { l.x=vx; l.y=vy; l.tim=nt+1; vis[vx][vy]=1; q.push(l); //q.push(vx,vy,nt+1{b}) } } } } cout<<-1; return ; } int main(){ memset(t,0x3f,sizeof(t)); scanf("%d",&m); for(int i=1;i<=m;++i) { scanf("%d%d%d",&xi,&yi,&ti); t[xi][yi]=min(ti,t[xi][yi]); safe[xi][yi]=1; for(int j=0;j<=3;++j){ if(xi+mx[j]>=0&&yi+my[j]>=0){ t[xi+mx[j]][yi+my[j]]=min(t[xi+mx[j]][yi+my[j]],ti); safe[xi+mx[j]][yi+my[j]]=1; } } } l.x=l.y=l.tim=0; q.push(l); bfs(); return 0; }
P2895 [USACO08FEB]流星雨Meteor Shower
标签:str com get out bsp ring namespace include problem
原文地址:https://www.cnblogs.com/For-Miku/p/12252715.html