为什么提交时会编译不过在codeblocks上面都可以运行
#include <stdio.h>
#include <stdlib.h>
#define max 0x3f3f3f;
int n,ax,ay,q,p;
int a[202][202],b[202][202];
int next[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
struct not
{
int x;
int y;
};
struct not que[10001];
void Init()
{
int i,j;
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
{
scanf("%d",&a[i][j]);
b[i][j]=max;
if(a[i][j]==-1)
{
ax=i;
ay=j;
}
if(a[i][j]==-2)
{
q=i;
p=j;
}
}
}
void bfs()
{
int head,tail,k,tx,ty,curx,cury,c;
head=1;
tail=1;
que[head].x=ax;
que[head].y=ay;
b[ax][ay]=0;
tail++;
while(head<tail)
{
curx=que[head].x;
cury=que[head].y;
for(k=0; k<=3; k++)
{
tx=que[head].x+next[k][0];
ty=que[head].y+next[k][1];
if(tx<1||tx>n||ty<1||ty>n)
continue;
if(a[tx][ty]==-2)
c=b[curx][cury];
else
c=b[curx][cury]+a[tx][ty];
if(b[tx][ty]>c)
{
b[tx][ty]=c;
que[tail].x=tx;
que[tail].y=ty;
// printf("%d ",b[tx][ty]);
tail++;
}
}
head++;
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
Init();
bfs();
printf("%d\n",b[q][p]);
}
return 0;
}
#include <stdlib.h>
#define max 0x3f3f3f;
int n,ax,ay,q,p;
int a[202][202],b[202][202];
int next[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
struct not
{
int x;
int y;
};
struct not que[10001];
void Init()
{
int i,j;
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
{
scanf("%d",&a[i][j]);
b[i][j]=max;
if(a[i][j]==-1)
{
ax=i;
ay=j;
}
if(a[i][j]==-2)
{
q=i;
p=j;
}
}
}
void bfs()
{
int head,tail,k,tx,ty,curx,cury,c;
head=1;
tail=1;
que[head].x=ax;
que[head].y=ay;
b[ax][ay]=0;
tail++;
while(head<tail)
{
curx=que[head].x;
cury=que[head].y;
for(k=0; k<=3; k++)
{
tx=que[head].x+next[k][0];
ty=que[head].y+next[k][1];
if(tx<1||tx>n||ty<1||ty>n)
continue;
if(a[tx][ty]==-2)
c=b[curx][cury];
else
c=b[curx][cury]+a[tx][ty];
if(b[tx][ty]>c)
{
b[tx][ty]=c;
que[tail].x=tx;
que[tail].y=ty;
// printf("%d ",b[tx][ty]);
tail++;
}
}
head++;
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
Init();
bfs();
printf("%d\n",b[q][p]);
}
return 0;
}
/////
不通过
您的代码已保存
编译错误:您提交的代码无法完成编译
a.cpp:7:1: error: declaration of anonymous struct must be a definition
struct not
^
a.cpp:7:1: warning: declaration does not declare anything [-Wmissing-declarations]
a.cpp:12:1: error: declaration of anonymous struct must be a definition
struct not que[10001];
^
a.cpp:12:1: warning: declaration does not declare anything [-Wmissing-declarations]
a.cpp:38:5: error: use of undeclared identifier 'que'
que[head].x=ax;
^
a.cpp:39:5: error: use of undeclared identifier 'que'
que[head].y=ay;
^
a.cpp:44:14: error: use of undeclared identifier 'que'
curx=que[head].x;
^
a.cpp:45:14: error: use of undeclared identifier 'que'
cury=que[head].y;
^
a.cpp:48:16: error: use of undeclared identifier 'que'
tx=que[head].x+next[k][0];
^
a.cpp:49:16: error: use of undeclared identifier 'que'
ty=que[head].y+next[k][1];
^
a.cpp:59:17: error: use of undeclared identifier 'que'
que[tail].x=tx;
^
a.cpp:60:17: error: use of undeclared identifier 'que'
que[tail].y=ty;
^
2 warnings and 10 errors generated.
编译错误:您提交的代码无法完成编译
a.cpp:7:1: error: declaration of anonymous struct must be a definition
struct not
^
a.cpp:7:1: warning: declaration does not declare anything [-Wmissing-declarations]
a.cpp:12:1: error: declaration of anonymous struct must be a definition
struct not que[10001];
^
a.cpp:12:1: warning: declaration does not declare anything [-Wmissing-declarations]
a.cpp:38:5: error: use of undeclared identifier 'que'
que[head].x=ax;
^
a.cpp:39:5: error: use of undeclared identifier 'que'
que[head].y=ay;
^
a.cpp:44:14: error: use of undeclared identifier 'que'
curx=que[head].x;
^
a.cpp:45:14: error: use of undeclared identifier 'que'
cury=que[head].y;
^
a.cpp:48:16: error: use of undeclared identifier 'que'
tx=que[head].x+next[k][0];
^
a.cpp:49:16: error: use of undeclared identifier 'que'
ty=que[head].y+next[k][1];
^
a.cpp:59:17: error: use of undeclared identifier 'que'
que[tail].x=tx;
^
a.cpp:60:17: error: use of undeclared identifier 'que'
que[tail].y=ty;
^
2 warnings and 10 errors generated.

