Iowa_BattleShip @ 2017-11-07 17:01:36
原本想重温一下广搜,就打这道广搜裸题,但调了好久一直爆零……too many or too few lines……什么鬼了……
#include<cstdio>
using namespace std;
int a[1010][1010],qx[20010],qy[20010],q[20010],l[5]={1,-1,0,0},r[5]={0,0,1,-1};
bool v[1010][1010];
int main()
{
int i,j,n,x,y,yy,xx,head=0,tail=1;
char c;
scanf("%d",&n);
scanf("%c",&c);
scanf("%c",&c);//因为洛谷Linux,数据在Windows下生成就有两个换行符,所以读两遍
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%c",&c);
a[i][j]=c-'0';
if(a[i][j])
v[i][j]=1;
}
scanf("%c",&c);
scanf("%c",&c);//同上
}
scanf("%d%d%d%d",&x,&y,&xx,&yy);
qx[tail]=x;
qy[tail]=y;
v[x][y]=1;
while(head<tail)
{
head++;
if(head==20000)
head=1;
x=qx[head];
y=qy[head];
for(i=0;i<=3;i++)
{
x+=l[i];
y+=r[i];
if(x>0&&x<=n&&y>0&&y<=n&&!v[x][y])
{
v[x][y]=1;
tail++;
if(tail==20000)
tail=1;
qx[tail]=x;
qy[tail]=y;
q[tail]=q[head]+1;
if(x==xx&&y==yy)
{
printf("%d",q[tail]);
return 0;
}
}
}
}
return 0;
}
by Iowa_BattleShip @ 2017-11-07 18:55:27
突然发现这道题交着交着,我的提交超400了……没法祭400啊啊啊(垃圾题目毁我青春)