hdu 6121---Build a tree(深搜+思维)】的更多相关文章

题目链接 Problem Description HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n−1, and the father of the node labeled i is the node labeled ⌊i−1k⌋. HazelFan wonders the size of every subtree, and you just need to tell him the XOR…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6121 题意:一个n个点的完全k叉树,求每个节点的size的异或和. 解法:容易发现,考虑根的所有孩子,最多只有一个不是满k叉树,我们只要把这个子节点作为临界点,其左边的就是满k叉树,其右边的便是比左边层数小一的满k叉树,那么我们每次只要算出中间这个非满k叉树的节点个数即可,然后对这个孩子进行递归处理.而其他子树由于是满k叉树,其数量可以提前预处理出来.这样处理在k>2的时候复杂度是logk(n)的,…
Build a tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 946    Accepted Submission(s): 369 Problem Description HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n−1…
http://acm.hdu.edu.cn/showproblem.php?pid=6121 题意:给你一颗完全K叉树,求出每棵子树的节点个数的异或和. 思路: 首先需要了解一些关于完全K叉树或满K叉树的一些知识: 对于每棵子树,只有三种情况: ①是满K叉树  ②不是满K叉树  ③叶子节点 并且非满K叉树最多只有一个,所以只需要将它进行特殊处理,具体看代码吧,说不清楚.代码参考了http://blog.csdn.net/my_sunshine26/article/details/77200282…
http://acm.hdu.edu.cn/showproblem.php?pid=6121 题目大意: 给你一颗 n 个节点的完全 k 叉树,问你这棵树中所有子树结点个数的总异或值. 分析: 我们很容易看到于发现对于这样的一颗树 , 肯定是只有一颗子树不是满k叉树 , 知道这样后 , 这就很简单了: 我们可以找到不满的树的编号P , 那左边就要(P-1)棵满树 , 右边有(n-P)棵少一层的满树 , 我们在分析,如果左边的树的数量是偶数 , 那我们可以不用计算 , 奇数只要计算一颗:右边同样的…
HazelFan wants to build a rooted tree. The tree has nn nodes labeled 0 to n−1, and the father of the node labeled i is the node labeled  . HazelFan wonders the size of every subtree, and you just need to tell him the XOR value of these answers. Input…
/** * 题意:一棵 n 个点的完全 k 叉树,结点标号从 0 到 n - 1,求以每一棵子树的大小的异或和. * 解法:k叉树,当k=1时,特判,用xorn函数,具体解释:http://blog.csdn.net/a3630623/article/details/12371727 * k不等一1:我们dfs求解,当是满k叉树,可以很快求的:每层最对可能三类树,少一层的满k叉树, * 少两层的满k叉树,不满的子树dfs求解. */ #include <cstdio> #include <…
Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angel's friends want to save Angel. Their task is: approa…
N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1757    Accepted Submission(s): 772   Problem Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上.你的任务是,对于给定的N,求出…
题目链接 Problem Description HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n−1, and the father of the node labeled i is the node labeled ⌊i−1k⌋. HazelFan wonders the size of every subtree, and you just need to tell him the XOR…