Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
1264 yy019 鸣人与佐助 C++ 输出超限 0 MS 268 KB 1156 2022-06-01 19:18:17

Tests(0/20):


#include <bits/stdc++.h> using namespace std; struct Point{ int x,y,t,step; }; int m,n,t; char c[205][205]; int vis[205][205]; int startx,starty,endx,endy; const int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0}; queue<Point> r; int main(){ cin>>m>>n>>t; for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ cin>>c[i][j]; if(c[i][j]=='@'){ startx=i,starty=j; } if(c[i][j]=='+'){ endx=i,endy=j; } } } Point start; start.x=startx; start.y=starty; start.step=0; start.t=t; r.push(start); bool flag=false; while(!r.empty()){ int x=r.front().x; int y=r.front().y; cout<<"x: "<<x<<" y: "<<y<<endl; int t=r.front().t; if(x==endx && y==endy && t>=0){ cout<<r.front().step; flag=true; break; } for(int i=0;i<4;i++){ int tx=x+dx[i]; int ty=y+dy[i]; cout<<"tx: "<<tx<<" ty: "<<ty<<endl; int tt=t; if(c[tx][ty]=='#') tt--; if(!vis[tx][ty] && t>=0){ Point temp; temp.x=tx; temp.y=ty; temp.t=tt; temp.step=r.front().step+1; r.push(temp); vis[tx][ty]=1; } } r.pop(); } if(!flag) cout<<-1; return 0; }


测评信息: