HDU 5573 Binary Tree【构造】】的更多相关文章

Binary Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5573 Description The Old Frog King lives on the root of an infinite tree. According to the law, each node should connect to exactly two nodes on the next level, forming a full binary tree. S…
几天前模拟区域赛的一道题,今天发现在草稿箱里直接补个博客. 感觉这还是一道很有意思的构造题. 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5573 题意: 给你一个二叉树,根节点为1,子节点为父节点的2倍和2倍+1,从根节点开始依次向下走k层,问如何走使得将路径上的数进行加减最终结果得到n. 分析: 首先明确由1.2.4...2k可以构造出所有小于2k+1的数,那么实际上只要走2的幂次即最左边的结点即可. 那么实际上这个过程就类似整数的二进制表…
http://acm.hdu.edu.cn/showproblem.php?pid=5573 题意:给出一个满二叉树,根节点权值为1,左儿子为2*val,右儿子为2*val+1.现在有只青蛙从根节点出发,一步步往下走,在每个节点它都要选择加上该点的权值还是减去该点的权值,如果正好经过k个节点时总的权值和为n,那么这只青蛙就成功了,需要输出方案. 思路: 这道题目要注意到n<=(1<<k). 所以如果每次都走这棵二叉树的左节点的话,权值就是1,2,4,8,10,那么它就可以组成小于(1&l…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5573 题目大意: 从1走到第k层,下一层的数是上一层的数*2或者*2+1,可以选择加上或者减去走的数,最终要求结果为n 输出每层走的数,和是加还是减 题目思路: [规律][贪心][数学] 首先苦思冥想一下,发现,1 2 4 8...2k可以凑成任意的奇数.而偶数只需要把2k变为2k+1. (从k往1位考虑加减,把+看为1,-看为0,则1+2+4+...=2k-1,符号可以用二进制数X表示,为111…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5573 题意:给你一个完全二叉树,节点为自然数的排列(第一行1,第二行2 3,第三行4 5 6 7...).现在,给你一个N和K,K表示给你这个完全二叉树的前K行,从第1行到第K行有很多路径,希望找到一条路径能表示N,路径上的节点可取正也可取负,要求最后的和为N. 思路:由题目给的数据范围可知前两个节点有一个一定可以表示N.(前两个节点可以表示1 - 2^k) code: #include <cstd…
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2442    Accepted Submission(s): 1063 Problem Description A binary tree is a finite set of vertices that is either empty or…
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9283    Accepted Submission(s): 4193 Problem Description A binary tree is a finite set of vertices that is either empty or…
题链;http://acm.hdu.edu.cn/showproblem.php?pid=1710 Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4205    Accepted Submission(s): 1904 Problem Description A binary tree i…
传送门 Description A binary tree is a finite set of vertices that is either empty or consists of a root r and two disjoint binary trees called the left and right subtrees. There are three most important ways in which the vertices of a binary tree can be…
题目链接 Problem Description You are given a complete binary tree with n nodes. The root node is numbered 1, and node x's father node is ⌊x/2⌋. At the beginning, node x has a value of exactly x. We define the value of a path as the sum of all nodes it pa…