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 spike_cn at 2012-09-22 13:07:31 on Problem 1145
void preorder(tree *T,int sum)
{
	if(flag==1)
		return ;
	if(T!=0)
	{
		sum+=T->data;
		if(sum==N&&T->left==0&&T->right==0)//当前和等于N并且左右结点都为空就说明该路径符合
		{
			flag=1;
			return;
		}
		preorder(T->left,sum);
		preorder(T->right,sum);
	}
}
这是我先建树再遍历的代码

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