Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
179816 刘睿甫 机器人搬重物 C++ 通过 100 1 MS 324 KB 1484 2024-08-21 12:51:56

Tests(10/10):


#include<bits/stdc++.h> #include<queue> using namespace std; int n,m; int dx[5]={0,-1,0,1,0}; int dy[5]={0,0,1,0,-1}; int abc[5]={0,1,2,1,0}; int a[60][60]; int f[60][60]; int b[60][60]; struct name{ int x,y; int op; int t; }; void change(){ for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(b[i][j]==1){ a[i-1][j-1]=1; a[i-1][j]=1; a[i][j-1]=1; a[i][j]=1; } } } } int main(){ cin>>n>>m; int op; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>b[i][j]; } } int sx,sy,ex,ey; cin>>sx>>sy>>ex>>ey; char s; cin>>s; change(); if(a[sx][sy]==1||a[ex][ey]==1){ printf("-1"); return 0; } if(sx==ex&&sy==ey){ printf("0"); return 0; } if(s=='N')op=1; else if(s=='E')op=2; else if(s=='S')op=3; else op=4; name start; start={sx,sy,op,0}; queue<name> q; q.push(start); while(q.size()){ name u=q.front(); q.pop(); for(int i=1;i<=4;i++){ int zhuan=u.op +i; if(zhuan==5)zhuan=1; if(zhuan==6)zhuan=2; if(zhuan==7)zhuan=3; if(zhuan==8)zhuan=4; int mi=abc[i]; for(int j=1;j<=3;j++){ int xx=u.x +dx[zhuan]*j; int yy=u.y +dy[zhuan]*j; if(xx<=0||xx>=n||yy<=0||yy>=m)break; if(a[xx][yy]==1)break; if(f[xx][yy]==0||f[xx][yy]>u.t +mi+1){ f[xx][yy]=u.t +mi+1; name l={xx,yy,zhuan,f[xx][yy]}; q.push(l); } } } } if(f[ex][ey]==0)printf("-1"); else printf("%d",f[ex][ey]); return 0; }


测评信息: