#include<stdio.h>
#include<string.h>
bool map[9][9]={
{1,1,1,1,1,1,1,1,1},
{1,0,0,1,0,0,1,0,1},
{1,0,0,1,1,0,0,0,1},
{1,0,1,0,1,1,0,1,1},
{1,0,0,0,0,1,0,0,1},
{1,1,0,1,0,1,0,0,1},
{1,1,0,1,0,1,0,0,1},
{1,1,0,1,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1}
};
bool vis[9][9];
int bx,by,ex,ey,ans;
void dfs(int x,int y,int cnt){
if(x<0||x>=9||y<0||y>=9||vis[x][y]||map[x][y]||cnt>=ans)
return ;
if(x==ex&&y==ey){
ans=cnt;
return ;
}
vis[x][y]=1;
dfs(x-1,y,cnt+1);
dfs(x+1,y,cnt+1);
dfs(x,y-1,cnt+1);
dfs(x,y+1,cnt+1);
vis[x][y]=0;
}
int main(){
int N;
scanf("%d",&N);
while(N--){
ans=90;
memset(vis,0,sizeof(bool));
scanf("%d%d%d%d",&bx,&by,&ex,&ey);
dfs(bx,by,0);
printf("%d\n",ans);
}
return 0;
}
nyoj58_最少步数
最新推荐文章于 2018-07-19 16:43:19 发布