码迷,mamicode.com
首页 >  
搜索关键字:smallest sub-array    ( 590个结果
UVA 12300 - Smallest Regular Polygon(计算几何)
思路:找对点最优,奇数情况下,半径要另外算 大概这么一个图,偶数就是距离的一半,奇数的话,做一个正2N边形,那么半径就可以利用三角函数算出来了 然后有了外切圆半径,就能算面积了,为sin(2pi / n) * r * r * n / 2 代码: #include #include #include #include using namespace std; const d...
分类:其他好文   时间:2015-03-28 08:49:01    阅读次数:133
UVa 11997 (优先队列 多路归并) K Smallest Sums
考虑一个简单的问题,两个长度为n的有序数组A和B,从每个数组中各选出一个数相加,共n2中情况,求最小的n个数。将这n2个数拆成n个有序表:A1+B1≤A1+B2≤...A2+B1≤A2+B2≤......An+B1≤An+B2≤...然后用优先队列合并成一个有序表即可。队列中需要记录两个数的和s,以...
分类:其他好文   时间:2015-03-16 16:10:15    阅读次数:129
D - K Smallest Sums(多路归并+贪心)
Problem KK Smallest SumsYou're given k arrays, each array has k integers. There are kk ways to pick exactly one element in each array and calculate th...
分类:其他好文   时间:2015-03-15 13:45:14    阅读次数:228
算法导论第三版   练习2.2-2
选择算法伪代码:forj=1ton-1 smallest=j fori=j+1ton ifA[i]<A[smallest] smallest=i A[j]=A[smallest] 循环不变式 在for循环(循环变量为j)的每次迭代开始,包含元素A[1..j-1]对的子数组都是排好序的(由数组[1..n]的j-1个最小元素组成) 循环终止的条件是就j>n-1,..
分类:编程语言   时间:2015-03-08 17:24:46    阅读次数:205
Smallest Difference (poj 2718 暴力枚举)
题意:给2~10个不同的数字,要求把这些数字分成两堆,每一堆任意组合成一个数(开头不能为0),求两个数差的最小值。 思路:数据很小,直接暴力枚举所有情况,并且很容易想到,要使差最小则这两个数的位数应该尽量相等;枚举排列时用到了next_permutation函数。...
分类:其他好文   时间:2015-03-03 22:16:38    阅读次数:265
HackerRank - The Maximum Subarray
Point: not necessarily contigous max sub array, at least one element should be selected:def maxSubarrCont(arr, n): ret = arr[0] curr = arr[0] ...
分类:其他好文   时间:2015-03-03 16:34:35    阅读次数:127
LeetCode[Tree]: Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST. Note: next()...
分类:其他好文   时间:2015-03-03 01:12:50    阅读次数:227
PAT1038. Recover the Smallest Number
Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can...
分类:其他好文   时间:2015-02-16 16:49:56    阅读次数:137
[LeetCode]Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST. Note...
分类:其他好文   时间:2015-02-15 18:12:12    阅读次数:175
sorting algorithm
SortingalgorithmSelection sortThis method is called selection sort because it works by repeatedly selecting the smallest remaining item。Selection sort...
分类:其他好文   时间:2015-02-09 22:46:57    阅读次数:286
590条   上一页 1 ... 49 50 51 52 53 ... 59 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!