liu2001 @ 2017-07-31 21:40:39
题目坑!
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
bool c[1001][1001]={0};
long pre[1000001];
struct s
{
long x,y;
}s[1000001];
long n,m;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
long ans=0;
void liu(int h)
{
ans++;
if(pre[h]!=1)
liu(pre[h]);
}
int main()
{
long i,j,head,tail,x0,y0,x,y;
bool f=0;
string r[1001];
scanf("%ld",&n);
for(i=1;i<=n;i++)
cin>>r[i];
m=r[1].length();
cin>>x0>>y0>>x>>y;
head=0;tail=1;
s[1].x=x0;
s[1].y=y0;
pre[1]=0;
c[x0][y0]=1;
while(head<tail)
{
head++;
for(int o=0;o<4;o++)
{
int a=s[head].x+dx[o];
int b=s[head].y+dy[o];
if(a>0&&a<=n&&b>0&&b<=m&&c[a][b]==0&&r[a][b]=='0')
{
tail++;
s[tail].x=a;
s[tail].y=b;
pre[tail]=head;
c[a][b]=1;
}
if(a==x&&b==y)
{
f=1;
break;
}
}
if(f==1) break;
}
liu(tail);
cout<<ans;
}
by 小手冰凉 @ 2017-09-23 14:12:44
如果站在终点上貌似没考虑