Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
1280 yy034 鸣人与佐助 C++ 解答错误 0 MS 280 KB 1244 2022-06-02 18:19:25

Tests(1/20):


#include <bits/stdc++.h> using namespace std; struct point{ int x,y; int step; int ck; }; int a[205][205]; int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0}; queue<point> r; int main(){ int n,m,k; int sx,sy,ex,ey; cin>>n>>m>>k; char t; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>t; switch(t){ case '@': a[i][j]=0; sx=i; sy=j; break; case '*': a[i][j]=1; break; case '+': a[i][j]=1; ex=i; ey=j; break; case '#': a[i][j]=2; break; } } } point start;start.ck=k;start.step=0;start.x=sx;start.y=sy; r.push(start); while(!r.empty()){ int tx=r.front().x,ty=r.front().y; if(tx==ex&&ty==ey){ cout<<r.front().step; return 0; } for(int i=0;i<4;i++){ if(a[tx+dx[i]][ty+dy[i]]==1){ point rt; a[tx+dx[i]][ty+dy[i]]=0; rt.x=tx+dx[i];rt.y=ty+dy[i]; rt.step=r.front().step+1;rt.ck=r.front().ck; r.push(rt); } else if(a[tx+dx[i]][ty+dy[i]]==2&&r.front().ck>0){ point rt; a[tx+dx[i]][ty+dy[i]]=0; rt.x=tx+dx[i];rt.y=ty+dy[i]; rt.step=r.front().step+1;rt.ck=r.front().ck-1; r.push(rt); } } r.pop(); } cout<<-1; return 0; }


测评信息: