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 771385494 at 2012-07-26 12:31:58 on Problem 2488
把每个点看做是一个时钟的终点,每个点有八个可能的走法,分别是1点钟方向,2,4,5,7,8,10,11.
题目要求按照字典序输出,则搜索顺序为8(-2,-1),10(-2,1),7(-1,-2),11(-1,2),5(1,-2),1(1,2),4(2,-1),2(2,1);算法如下:

bool FindPath(int a,int b)
{
	path[index++] = (a + 'A' - 1);
	path[index++] = (b + '0');
	visited[a][b] = 1;
	if(a - 2 >= 1 && b - 1 >= 1 && visited[a - 2][b - 1] == 0 && FindPath(a - 2,b - 1))//8 clock
		return true;
	if(a - 2 >= 1 && b + 1 <= height && visited[a - 2][b + 1] == 0 && FindPath(a - 2,b + 1))//10 clock
		return true;
	if(a - 1 >= 1 && b - 2 >= 1 && visited[a - 1][b - 2] == 0 && FindPath(a - 1,b - 2))//7 clock
		return true;
	if(a - 1 >= 1 && b + 2 <= height && visited[a - 1][b + 2] == 0 && FindPath(a - 1,b + 2))//11 clock
		return true;
	if(a + 1 <= width && b - 2 >= 1 && visited[a + 1][b - 2] == 0 && FindPath(a + 1,b - 2))//5 clock
		return true;
	if(a + 1 <= width && b + 2 <= height && visited[a + 1][b + 2] == 0 && FindPath(a + 1,b + 2))//1 clock
		return true;
	if(a + 2 <= width && b - 1 >= 1 && visited[a + 2][b - 1] == 0 && FindPath(a + 2,b - 1))//4 clock
		return true;
	if(a + 2 <= width && b + 1 <= height && visited[a + 2][b + 1] == 0 && FindPath(a + 2,b + 1))//2 clock
		return true;
	return false;
}
but,WA掉了,,,这题目到底是怎么一个情况,求解释啊

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