Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.难度70,与Convert Sorted Array to Binary Sear...
分类:
其他好文 时间:
2014-09-08 06:26:16
阅读次数:
263
整合两道差不多的题目放上来,其中第一题是第二题的基础。
1.
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...
分类:
其他好文 时间:
2014-09-06 21:21:03
阅读次数:
279
Problem Description:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
分析:很容易想到的一种解法是将链表中所有的元素保存到数组中,然后每次取中间值进行构造,时间复杂度为O(n),空间复杂度为O(n)。具体...
分类:
其他好文 时间:
2014-09-05 18:14:11
阅读次数:
223
题目链接:
题意:
给定n个人 m个逃生洞穴 至少k个人进入逃生洞穴 挖洞时间c
下面n*m的矩阵表示每个人到每个洞需要的时间。
一个洞穴开始只能容纳一个人,可以被拓展一次,即变成可以容纳2个人(一个洞穴只能被拓展一次)
当a进入洞穴后不会开始拓展,直到有一个人b在洞穴门口等,a才会开始拓展空间,拓展的时间的c,c时间后b才能进入洞穴。
问至少k个人进入洞穴的最短时间。(数据保...
分类:
其他好文 时间:
2014-09-05 11:24:41
阅读次数:
148
递归 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode...
分类:
其他好文 时间:
2014-09-04 22:16:00
阅读次数:
228
题目链接:点击打开链接
题意:
rt。。
在询问时,两端向上爬时记录从深度浅的到深度深的方向上的 (也就是左最大连续子段和)
最后两个点在同一条重链上时合并。
合并时要注意有4种情况, 详见代码。
线段树部分和5相似。
#include
#include
#include
#include
using namespace std;
inline void rd(int &n)...
分类:
其他好文 时间:
2014-09-02 14:14:54
阅读次数:
235
最大子段和的各种形式
题解内附每道题的 题意 题目链接 思路
SPOJ 1043 GSS1
静态区间求个最大子段和,
题解
SPOJ 1577 GSS2
和1一样,区别是若区间内存在相同的元素,则该元素只计算一次。
离线一下然后使劲跑。。
题解
SPOJ 1716 GSS3
和1一样,就是要支持单点修改
题解
SPOJ 2713 GS...
分类:
其他好文 时间:
2014-09-02 14:12:45
阅读次数:
222
题意一开始不是很明确, 后来发现是每一种特征出现的次数相同这样一来就变成简单hash问题了,如果把每个特征看看做是一个(n+1)进制数的话,对奶牛序列求一下前缀和,如果i - j这一段每一种特征出现的次数相同的话,把i - 1点和j点的每一位减去所有位中的最小值之后,必然相等,所以hash判断一下就...
分类:
其他好文 时间:
2014-09-01 21:10:03
阅读次数:
227
题目链接:点击打开链接
题意:
T个测试数据
n个数字
q个询问
每个询问 : [x1, y1] [x2, y2]
问:
int ans = -inf;
for(int i = x1; i <= y1; i++)
for(int j = max(x2, i); j <= y2; j++)
ans = max(ans, query(i, j));
#include
#inc...
分类:
其他好文 时间:
2014-09-01 17:50:03
阅读次数:
227
题目链接:点击打开链接
题意:
给定n长的序列
下面2个操作
0 x y 给[x,y]区间每个数都 sqrt
1 x y 问[x, y] 区间和
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long...
分类:
其他好文 时间:
2014-09-01 10:47:03
阅读次数:
223