原题:
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of
every node never...
分类:
其他好文 时间:
2014-08-13 15:03:31
阅读次数:
261
bfs基础算法水题
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int Max = 1e5+50;
int dist[Max];
vector tree[Max];
int N, D, T;
void init()
{
for(int i = 0; ...
分类:
其他好文 时间:
2014-08-13 14:56:06
阅读次数:
187
使用cout<<setiosflags(ios::right)以后,再调用 cout<<setiosflags(ios::left);无效的,你可以在调用之前加上一句 cout<<resetiosflags(ios::right);清除右对齐以后在调用 cout<<setiosflags(ios::...
分类:
编程语言 时间:
2014-08-13 14:48:06
阅读次数:
417
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum =...
分类:
其他好文 时间:
2014-08-13 14:39:26
阅读次数:
153
注:这道题思路很乱,先记下,日后理清题意:给出一些节点,判断这些节点构成的是不是一棵树思路:感觉很简单,但是思路又很乱,当时想的判断条件是:1.入度不能大于1(树根为0,其他节点为1)2.所有节点必须在一棵树中(判断所有节点是否在一棵树中)3.在节点相连的时候,不能是同一棵树中的节点(否则会出现环或...
分类:
其他好文 时间:
2014-08-13 14:27:36
阅读次数:
224
Populate each next pointer to point to its next right node.
二叉树的结构体里增加了next指针,编写程序,将二叉树里每个节点的next指针指向它右边的节点。...
分类:
其他好文 时间:
2014-08-13 13:16:36
阅读次数:
210
Right-click on the module, select "Add framework support...", and check the "Maven" technology. (This also creates a?pom.xml?for you to modify.) If you mean adding source repository elements, I ...
分类:
其他好文 时间:
2014-08-13 10:44:45
阅读次数:
1136
hdu 4929 Another Letter Tree(LCA+DP)
题意:有一棵树n个节点(n
解法:一个很直观的想法,求出lca(设其为w)后,枚举x,求出a到w的路径上,能匹配s0的x长度前缀的情况有多少种,令其为c[x]。再求出b到w的路径上能匹配s0的L-x(L表示s0的长度)长度后缀的情况有多少种,令其为d[l-x],那么将所有的c[x]*d[l-x](x属于[0,l]...
分类:
其他好文 时间:
2014-08-13 10:38:05
阅读次数:
346
hdu4921 Map(状压统计)
题意:有10条长度不超过1000链,链上的节点有权值。我们从这些节点中选出一些节点来,若要选节点u,则u的前继都得被选进去。对于某一种选定的情况,我们能获得的权值为,选定的节点的权值和,以及一些附加值。附加值的求法为,对于每条链的同一深度的点,若选定的点的个数超过1,那么会得到的附加值为(si*xi/ci),其中si表示该层选中的点的权值和,xi为该层选中...
分类:
其他好文 时间:
2014-08-13 10:37:45
阅读次数:
193
1 class Solution { 2 public: 3 vector postorderTraversal(TreeNode *root) { 4 if(root->left == NULL && root->right == NULL) 5 { 6 ...
分类:
其他好文 时间:
2014-08-13 10:16:05
阅读次数:
168