题意:定义一个数为“balanced number” 当其满足存在一个数位pos(平衡点),在pos左边的数位的值乘与pos位的距离值的总和等于右
边的数位的值乘与pos位的距离值的总和,给定一个区间[l , r],求区间内有多少个balanced number。
思路:设dp[ pos ][ i ][ j ]表示平衡点在i位的情况下,当前考虑pos位,之前已形成的力矩为j(数乘以距离平衡点的...
分类:
其他好文 时间:
2015-01-24 18:49:44
阅读次数:
131
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路比较简单,就是每次以中位数为根节点,然后左边即左子树,右边是右子树,递归下去即可超时代码(不知道为啥)...
分类:
其他好文 时间:
2015-01-23 19:56:34
阅读次数:
202
题目大意:给定长度为N的字符串,求出其中不相同子串的个数。
解题思路:每一个字串一定是某个后缀的前缀,那么原问题就可以等价于求所有后缀之间的不相同的前缀的个数。如果所有的后缀按照suffix(sa[1]),suffix(sa[2])……suffix(sa[n])的顺序计算,我们会发现对于每个新加进来的后缀suffix(sa[k]),它将产生n-sa[k]+1个新的前缀。但是其中有leight[k...
分类:
编程语言 时间:
2015-01-22 20:18:15
阅读次数:
276
引言本文来自于Google的一道题目:how to merge two binary search tree into balanced binary search tree.how to merge two binary search tree into balanced binary searc...
分类:
其他好文 时间:
2015-01-22 14:39:12
阅读次数:
207
引言本文来自于Google的一道题目:how to merge two binary search tree into balanced binary search tree.how to merge two binary search tree into balanced binary searc...
分类:
其他好文 时间:
2015-01-22 13:15:23
阅读次数:
129
题目大意:给出一些字符串,给出一些询问,每次问当前串在源串中的几个中出现过。
思路:将所有源串建立广义后缀自动机。每次新的一个串的时候,把last清成root,往里面加的时候,如果last指针往下走的时候已经有节点了,就需要拓展一个新的节点出来,否则就不满足广义后缀自动机的性质。此外,每一个节点代表的不一定是一个串,可能代表的是多个串的子串,所以要在每个点后面挂链,来表示这个节点是属于哪...
分类:
其他好文 时间:
2015-01-21 11:52:46
阅读次数:
1125
点分治 点分治的例题2(本题代码结果为TLE……) 强烈谴责卡时限QAQ,T了无数次啊无数次…… 不过在N次的静态查错中倒是加深了对点分治的理解……也算因祸得福吧(自我安慰一下) 1 //SPOJ 1825 2 #include 3 #include 4 #include 5 #in...
分类:
其他好文 时间:
2015-01-21 01:15:08
阅读次数:
242
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:递归的思路。思路与重建二叉树类似。时间复杂度O(n), 空间复杂度O(logN) 1 /** 2 ....
分类:
其他好文 时间:
2015-01-20 22:00:43
阅读次数:
170
(http://leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html)Given a singly linked list where elements are sorted in ascending order, conv...
分类:
其他好文 时间:
2015-01-18 22:18:49
阅读次数:
202
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.思路:题目看上去好像很难,但实际上很简单,递归做就行,每次找到左右子树对应的子链表...
分类:
其他好文 时间:
2015-01-18 21:03:17
阅读次数:
241