本地样例过了,编译也是成功的,但是洛谷评测上却编译失败了,求调
#include<bits/stdc++.h>
using namespace std;
int wx[8]={-2,-2,-1,1,2,2,1,-1};
int wy[8]={-1,1,2,2,1,-1,-2,-2};
int T;
int flag,success,sx,sy;
char goalmap[5005][5005]={
{'0','0','0','0','0','0'},
{'0','1','1','1','1','1'},
{'0','0','1','1','1','1'},
{'0','0','0','*','1','1'},
{'0','0','0','0','0','1'},
{'0','0','0','0','0','0'},
};
char nowmap[5005][5005];
int des()
{
int cnt=0;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
if(goalmap[i][j]!=nowmap[i][j])
{
cnt++;
}
}
}
return cnt;
}
void A_star(int dep,int x,int y,int maxdep)
{
if(dep==maxdep)
{
if(!des())
{
success=1;
}
return;
}
for(int i=0;i<8;i++)
{
int xx=x+wx[i];
int yy=y+wy[i];
if(xx>=1&&xx<=5&&yy>=1&&yy<=5)
{
swap(nowmap[x][y],nowmap[xx][yy]);
int deses=des();
if(deses+dep<=maxdep)
{
A_star(dep+1,xx,yy,maxdep);
}
swap(nowmap[x][y],nowmap[xx][yy]);
}
}
}
int main()
{
cin>>T;
while(T--)
{
flag=0;
success=0;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
cin>>nowmap[i][j];
if(nowmap[i][j]=='*')
{
sx=i;
sy=j;
}
}
}
for(int maxdep=1;maxdep<=15;maxdep++)
{
A_star(0,sx,sy,maxdep);
if(success)
{
cout<<maxdep<<endl;
flag=1;
break;
}
}
if(!flag)
{
cout<<"-1"<<endl;
}
}
return 0;
}