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...
分类:
其他好文 时间:
2015-01-08 12:57:43
阅读次数:
171
The problem:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.My analysis:The recursion is the best way...
分类:
其他好文 时间:
2015-01-08 00:49:30
阅读次数:
265
1811. Longest Common SubstringProblem code: LCSA string is finite sequence of characters over a non-empty finite set Σ.In this problem, Σ is the set o...
分类:
其他好文 时间:
2015-01-07 23:22:12
阅读次数:
154
2666. Query on a tree IVProblem code: QTREE4You are given a tree (an acyclic undirected connected graph) with N nodes, and nodes numbered 1,2,3...,N. ...
分类:
其他好文 时间:
2015-01-07 00:31:02
阅读次数:
266
https://oj.leetcode.com/problems/balanced-binary-tree/http://blog.csdn.net/linhuanmars/article/details/23731355/**
*Definitionforbinarytree
*publicclassTreeNode{
*intval;
*TreeNodeleft;
*TreeNoderight;
*TreeNode(intx){val=x;}
*}
*/
publicclassSolution{
publ..
分类:
其他好文 时间:
2015-01-06 15:46:32
阅读次数:
125
我的树分治#3.After the success of 2nd anniversary (take a look at problem FTOUR for more details), this 3rd year, Travel Agent SPOJ goes on with another di...
分类:
其他好文 时间:
2015-01-05 21:39:40
阅读次数:
160
题解:考虑枚举gcd,然后问题转化为求 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #include12 #define inf 100000...
分类:
其他好文 时间:
2015-01-03 13:09:15
阅读次数:
385
题目大意:给定n,求LCM(1,n)+LCM(2,n)+...+LCM(n,n)
枚举d=GCD(i,n),令F(n)为n以内与n互质的数之和
则ans=Σ[d|n]d*F(d)*n/d=nΣF(d)
现在就是F(n)的问题了 我们发现对于任意n>=3,如果x与n互质,那么n-x一定与n互质
故n以内与n互质的数能两两凑成和为n的数对,一共φ(n)/2对,故F(n)=n*φ(n)/2
注...
分类:
其他好文 时间:
2015-01-01 16:06:27
阅读次数:
156
首先发现每一位二进制可以分开来做。然后就变成0、1两种数了,考虑最小割。设S表示选0,T表示选1,则对于确定的点向数字对应的S/T连边,边权inf;然后原来图中有边的,互相连边,边权为1。直接最小割即可,最后还要dfs一下来求出每个未确定的数选的是0还是1。 1 /****************....
分类:
其他好文 时间:
2014-12-31 22:43:56
阅读次数:
279
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.分析:对于BST,左右子树的高度差小于等于1,则在由sorted array构建BST时把数组中间元素作为...
分类:
其他好文 时间:
2014-12-31 16:04:01
阅读次数:
198