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 |
找不到哪错了#include<stdio.h> #include<string.h> int q[2000],size,head,tail; int step[9][9]; int dir[][2]={{-1,-2},{-2,-1},{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2}}; void enque(int a,int b) { tail=(tail++)%2000; q[tail]=a; tail=(tail++)%2000; q[tail]=b; size++; } void deque(int *a,int*b) { head=(head++)%2000; *a=q[head]; head=(head++)%2000; *b=q[head]; size--; } void search(int desa,int desb) { int a,b,i,j; while(size) { deque(&a,&b); if(a==desa&&b==desb) break; for(i=0;i<8;i++) { if(!(a<1||b<1||a>8||b>8)&&step[a+dir[i][0]][b+dir[i][1]]==0) { enque(a+dir[i][0],b+dir[i][1]); step[a+dir[i][0]][b+dir[i][1]]=step[a][b]+1; } } } return; } int main() { int i,j; char a[3],b[3]; while(scanf("%s%s",a,b)!=EOF) { memset(step,0,sizeof(step)); size=head=tail=step[1][1]=0; enque(a[0]-'a'+1,a[1]-'0'); search(b[0]-'a'+1,b[1]-'0'); printf("To get from %s to %s takes %d knight moves.\n",a,b,step[b[0]-'a'+1][b[1]-'0']); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator