Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
1039 yy022 鸣人与佐助 C++ 解答错误 0 MS 280 KB 1384 2022-05-28 10:40:30

Tests(0/20):


#include <iostream> using namespace std; struct node{ int x,y,step,t; }q[10001]; char a[101][101]; int b[101][101]; int nexts[4][2] = {{0,1},{0,-1},{1,0},{-1,0}}; int n,m,t,sy,sx,qx,qy,tx,ty; int head = 1,tail = 1,flag = 0; void bfs(){ q[tail].x = sx; q[tail].y = sy; q[tail].step = 0; tail++; b[sx][sy]=1; while(head<tail){ for(int i=0;i<4;i++){ tx = q[head].x+nexts[i][0]; ty = q[head].y+nexts[i][1]; if(tx<1 || tx>n || ty<1 || ty>m){ continue; } if(a[tx][ty] == '*' && b[tx][ty]==0){ q[tail].x = tx; q[tail].y = ty; q[tail].step = q[head].step+1; tail++; b[tx][ty] = 1; } if(a[tx][ty] == '#' && b[tx][ty] == 0 && t>0){ q[tail].x = tx; q[tail].y = ty; q[tail].step = q[head].step+1; tail++; b[tx][ty] = 1; t--; } if(tx == qx && ty == qy){ flag = 1; break; } } if(flag){ break; } head++; } } int main(){ cin>>n>>m>>t; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; if(a[i][j] == '@'){ sx = i; sy = j; } if(a[i][j] == '+'){ qx = i; qy = j; } } } bfs(); cout<<qx+1<<" "<<qy+1<<endl; if(t<=0 && a[qx+1][qy] == '#' && a[qx-1][qy] == '#' && a[qx][qy+1] == '#' && a[qx][qy-1] == '#'){ cout<<-1; return 0; } cout<<q[tail-1].step; return 0; }


测评信息: