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

用数组模拟二叉树,结点数肯定是2的一个幂,所以,向上靠拢

Posted by userfriendly at 2009-03-22 16:43:44 on Problem 2352 and last updated at 2009-03-22 16:46:12
In Reply To:Xiedie的解题报告里面,const int MAXX = 32000; //最大范围, int f[(MAXX+1)*3] //节点值. 为什么f是(MAXX+1)*3? 对于有n个节点的二叉树,*2不就够了吗? Posted by:Lucifer at 2005-09-05 08:09:57
*3是用多了空间的,*2很可能是空间不足的

要用N个结点,就要取  2^(log2(N)向上取整)这么个大小的数组,树根在数组下标0的话,左儿子在r*2+1, r*2+2,用惯了树根在1就+10安全第一 ~~~~~

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