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 17:45:50
求救
by Iowa_BattleShip @ 2017-11-07 17:47:54
I need help……
by Iowa_BattleShip @ 2017-11-07 18:04:08
有人么…………有大佬么…………
by Lolierl @ 2017-11-07 18:17:01
@Iowa_BattleShip 您的读入有点冒险,建议不要这么读
by Iowa_BattleShip @ 2017-11-07 18:20:13
@Lolierl
我知道,然后我改成char数组用scanf读入,还是一样的结果
by Lolierl @ 2017-11-07 18:37:23
@Iowa_BattleShip
循环队列应该是head!=tail
by Iowa_BattleShip @ 2017-11-07 18:39:50
@Lolierl
改了,还是一样爆零……
by Lolierl @ 2017-11-07 18:48:28
@Iowa_BattleShip
"x+=l[i]""y+=r[i]"然而x和y在循环里已经动过了
by Iowa_BattleShip @ 2017-11-07 18:53:17
@Lolierl
感谢感谢,对的,x,y不应自加,我已经A了(完了,那么粗心NOIP必定爆零……)
谢谢dalao
by Lolierl @ 2017-11-07 18:55:04
@Iowa_BattleShip
我不是dalao啊···
给您推荐一位叫做@sonorous 的dalao