| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
在浙大AC,这里WA,WHY????#include <stdio.h>
#include <string.h>
struct node
{
int x,y;
int step;
};
int xi[]={-2,-2,-1,1,2,2,1,-1};
int yi[]={-1,1,2,2,1,-1,-2,-2};
int startx,starty,endx,endy;
int main()
{
int test,i;
int a[8][8];
char s1[3],s2[3];
while(scanf("%s %s",s1,s2)!=EOF) {
startx=s1[0]-'a';
starty=s1[1]-'1';
endx=s2[0]-'a';
endy=s2[1]-'1';
memset(a,0,sizeof(a));
struct node n;
n.x=startx,n.y=starty;
n.step=0;
struct node b[10000];
b[0]=n;
int front=0,rear=1;
while(front!=rear)
{
n=b[front];
if(n.x==endx&&n.y==endy)
break;
front=(front+1)%10000;
for(int j=0;j<8;j++)
{
struct node p;
p.x=n.x+xi[j],p.y=n.y+yi[j];
p.step=n.step+1;
if(p.x>=0&&p.x<8&&p.y>=0&&p.y<8&&!a[p.x][p.y])
{
b[rear]=p;
rear=(rear+1)%10000;
a[p.x][p.y]=1;
}
}
}
printf("To get from e2 to e4 takes %d knight moves.\n",n.step);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator