p; // 起始坐标入正向队列
next.x = end_x;
next.y = end_y;
vis[end_x][end_y] = 2; // 设置逆向探索标记为2
q2[rear2++] = next; // 终点坐标入逆向队列
while (front1 < rear1 && front2<rear2)
{
if (rear1-front1 < rear2-front2)
{
cur = q1[front1++]; flag=1; // 扩展正向队列
}
else
{
cur = q2[front2++]; flag=2; // 扩展逆向队列
}
for (i=0; i<8; ++i)
{
next.x = cur.x + dx[i];
next.y = cur.y + dy[i];
if (next.x<0 || next.x>=n || next.y<0 || next.y>=n)
continue;
if (!vis[next.x][next.y])
{
vis[next.x][next.y] = flag;
step[next.x][next.y] = step[cur.x][cur.y] + 1;
if (flag==1)
q1[rear1++] = next;
else
&n