求问为什么不对啊!!!

P1746 离开中山路

请在代码前后打上"```"三个点,现在这个样子这样没法看没法debug
by BCtt_YDLee @ 2018-07-12 08:24:50


@[ADtt_YDLee](/space/show?uid=59631) ```#include<bits/stdc++.h> using namespace std; int n,s1,s2,t1,t2; int used[1001][1001]; int dx[4]={0,0,-1,+1},dy[4]={-1,+1,0,0}; struct point{ int x,y,step; }; int main(){ scanf("%d",&n); char c; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { cin>>c; if(c=='1') used[i][j]=0; else used[i][j]=1; } scanf("%d %d %d %d",&s1,&s2,&t1,&t2); point q[1000001],u,v; int head=1,tail=1; q[head].x=s1,q[head].y=s2,q[head].step=0; used[s1][s2]=1; while(head<=tail){ u=q[head]; for(int i=0;i<=3;i++){ v.x=u.x+dx[i],v.y=u.y+dy[i],v.step=u.step+1; if(v.x>n||v.x<1||v.y>n||v.y<1||used[v.x][v.y]==1) continue; if(v.x==t1&&v.y==t2){ printf("%d",v.step); return 0; } used[v.x][v.y]=1; tail++; q[tail]=v; } head++; } return 0; } ```
by Ellen @ 2018-07-15 20:49:57


您这个。。。很明显,数组有第零位,所以 ``` int dx[4]={0,0,-1,+1},dy[4]={-1,+1,0,0}; ``` 应该是 ``` int dx[5]={0,0,0,-1,1},dy[5]={0,-1,1,0,0}; ```
by BCtt_YDLee @ 2018-07-15 23:05:27


@[Ellen](/space/show?uid=28545) 两个问题 1.那么大的数组直接在函数里开直接RE 2.跑答案那部分过于混乱 刚刚没细看。。。在这里抱歉
by BCtt_YDLee @ 2018-07-15 23:21:24


@[ADtt_YDLee](/space/show?uid=59631) 请问为什么很大的数组不能在函数里开
by Ellen @ 2018-07-16 19:46:19


emmm 这个吧。。。每个函数的空间不是特别大,开了就会被系统杀死 开在外面,每个都被赋值为0,而且外面空间比较大。 感性理解,记住就好,我是炸过N次之后记住的。。。。。。。。。。。。。。。。。。
by BCtt_YDLee @ 2018-07-16 20:06:12


|