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

大牛帮帮忙啊,为什么会WA啊!

Posted by captial at 2009-10-31 19:12:17 on Problem 1915
这是我的代码,怎么不对啊?哪位大牛帮忙看看啊!
#include <iostream>
using namespace std;

int dir[8][2]={{-2,-1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}};

int main()
{
	int Tcase;
	scanf("%d",&Tcase);
	while(Tcase--)
	{
		int n,sx,sy,ex,ey;
		bool map[310][310]={0};
		int step[310][310]={0};
		scanf("%d",&n);
		scanf("%d%d",&sx,&sy);
		scanf("%d%d",&ex,&ey);
		if(sx==ex && sy==ey)
		{
			printf("0\n");
			continue;
		}
		else
		{
			bool flag = false;
			int front,rear;
			front = 0,rear = 0;
			int queue[90100][2];
			queue[front][0] = sx,queue[front][1] = sy;
			map[sx][sy] = 1;
			while(front <= rear)
			{
				int x = queue[front][0];
				int y = queue[front][1];
				for(int i=0; i<8; i++)
				{
					int xx = x + dir[i][0];
					int yy = y + dir[i][1];
					if(xx>=0 && xx<=n-1 && yy>=0 && yy<=n-1)
					{
						if(map[xx][yy]==0)
						{
							map[xx][yy] = 1;
							step[xx][yy] = step[x][y]+1;
							rear++;
							queue[rear][0] = xx;
							queue[rear][1] = yy;
							if(xx == ex && yy == ey)
							{
								flag = true;
								break;
							}
						}
					}
				}
				if(flag)
					break;
				front++;
			}
			printf("%d\n",step[ex][ey]);
		}
	}
	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