Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求牛人指点一下我到底那里错了!

Posted by hdjay at 2011-04-09 00:17:30 on Problem 1915 and last updated at 2011-04-09 00:19:00
#include<stdio.h>
#include<string.h>
typedef struct
{
	int x,y,next;
}POINT;
int yy[8]={1,2,2,1,-1,-2,-2,-1};
int xx[8]={-2,-1,1,2,2,1,-1,-2};
int main()
{
	int n,l,first,last,i,s_x,s_y,e_x,e_y,count,a[300][300],col,row;
	POINT b[10000];
	freopen("input.txt","r",stdin);
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&l);
		scanf("%d %d",&s_x,&s_y);
		scanf("%d %d",&e_x,&e_y);
		memset(a,0,sizeof(a));
		first=last=0;
		count=0;
		b[0].x=s_x;
		b[0].y=s_y;
		a[0][0]=1;
		while(1)
		{
			if(b[first].x==e_x&&b[first].y==e_y)break;
			else
			{	
				for(i=0;i<8;i++)
				{
					 row=b[first].x+xx[i];
					 col=b[first].y+yy[i];
					if(col<l&&col>=0&&row<l&&row>=0&&a[row][col]==0)
					{
						last=last+1;
						b[last].x=b[first].x+xx[i];
						b[last].y=b[first].y+yy[i];
						b[last].next=first;
						a[row][col]=1;
					}
				}
				first=first+1;
			}
		}
		i=first;
		while(!(b[i].x==s_x&&b[i].y==s_y))
		{
			i=b[i].next;
			count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator