随机增量算法(a randomized incremental algorithm)#define sqr(x) ((x)*(x))#define EPS 1e-4struct P{ double x, y; P(double x, double y):x(x),y(y){} P(...
分类:
其他好文 时间:
2015-11-18 21:18:44
阅读次数:
224
题意: 寻找一棵BST中的第k小的数。思路: 递归比较方便。 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * ...
分类:
其他好文 时间:
2015-11-04 21:04:21
阅读次数:
296
题意: x[i]=(x[i-3]+x[i-2]+x[i-1])%m+1,求一段x的最短的连续子序列,使得这个子序列包含正整数【1,k】。分析: 扫描一遍即可,用一个队列记录下【1,k】区间内的数的位置,再用一个变量count维护【1,k】内不重复数的个数。当count等于k时说明当前序列已经满足.....
分类:
其他好文 时间:
2015-11-02 11:43:36
阅读次数:
169
题目:
Given a binary search tree, write a function kthSmallest to find the kth
smallest element in it.
Note:
You may assume k is always valid, 1 ≤ k ≤ BST's total elements.
Follow up:
Wh...
分类:
其他好文 时间:
2015-10-30 10:52:12
阅读次数:
170
//EXERCISE 2.1//Write a program that reads integers from the standard input until the end of file and then prints the largest and the smallest values ...
分类:
编程语言 时间:
2015-10-25 19:08:44
阅读次数:
174
Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's tota...
分类:
其他好文 时间:
2015-10-25 13:36:39
阅读次数:
131
枚举两个排列以及有那些数字,用dfs比较灵活。dfs1是枚举长度短小的那个数字,dfs2会枚举到比较大的数字,然后我们希望低位数字的差尽量大,后面最优全是0,如果全是0都没有当前ans小的话就剪掉。(第1个dfs完了,忘了加return。。。#include#include#include#incl...
分类:
其他好文 时间:
2015-10-18 17:00:39
阅读次数:
179
A variantion to "largest\smallest consecutive subarray". Idea is, at position i, the current max diff is max(max_left[i] - min_right[i+1], max_right[i...
分类:
其他好文 时间:
2015-10-18 14:01:57
阅读次数:
174
QuestionGiven a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BS...
分类:
其他好文 时间:
2015-10-10 09:05:45
阅读次数:
274
(referrence: GeeksforGeeks, Kth Largest Element in Array)This is a common algorithm problem appearing in interviews.There are four basic solutions.Sol...
分类:
其他好文 时间:
2015-10-10 01:33:06
阅读次数:
208