1. 概述
RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j当然,该问题也可以用线段树(也叫区间树)解决,算法复杂度为:O(N)~O(logN),这里我们暂不介绍。
2.RMQ算法
对于该问题,最容易想到的解决方案是遍历,复杂度是O(n)。但当数据量非常大...
分类:
其他好文 时间:
2014-10-25 21:36:10
阅读次数:
218
题目
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node....
分类:
其他好文 时间:
2014-10-25 18:50:01
阅读次数:
137
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[?2,1,?3,4,?1,2,1,...
分类:
其他好文 时间:
2014-10-24 18:14:41
阅读次数:
180
题目描述:
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
解题思路:直接DFS。
代码:
/**...
分类:
其他好文 时间:
2014-10-24 13:04:21
阅读次数:
147
Find the contiguous subarray within an array (containing at least one number) which has the largest product.
For example, given the array [2,3,-2,4],
the contiguous subarray [2,3] has the largest pr...
分类:
编程语言 时间:
2014-10-24 13:01:16
阅读次数:
222
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4],the...
分类:
其他好文 时间:
2014-10-24 10:26:11
阅读次数:
269
题目:给你一组数,求出其中两两最大公约数中最大的值。
分析:数论。数据较小,直接枚举即可。
说明:注意输入格式。
#include
#include
#include
using namespace std;
int data[101];
int gcd(int a, int b)
{
return a%b?gcd(b, a%b):b;
}
int main()
{
int...
分类:
其他好文 时间:
2014-10-23 16:24:39
阅读次数:
348
Maximum Product SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given...
分类:
其他好文 时间:
2014-10-22 19:51:21
阅读次数:
272
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4],the...
分类:
其他好文 时间:
2014-10-22 14:29:45
阅读次数:
171
Given a binary tree,find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest lea...
分类:
其他好文 时间:
2014-10-21 22:58:39
阅读次数:
235