摘要: 1 template 2 void percolatedown(T a[], int n, int i) 3 { 4 T tm = a[i]; 5 int child = i a[child+1]) 9 child++;10 if (tm >... 阅读全文
posted @ 2015-03-15 20:37 David_W 阅读(132) 评论(0) 推荐(0)
摘要: 代码1: 1 #include 2 #include 3 using namespace std; 4 const int MIN=0x80000000; 5 const int N=3; //物品数量 6 const int V=5; //背包容量 7 int f[N+1][V+1]; ... 阅读全文
posted @ 2015-03-15 19:44 David_W 阅读(150) 评论(0) 推荐(0)
摘要: 1 2 import java.util.Random; 3 4 public class LCS{ 5 public static void main(String[] args){ 6 7 //设置字符串长度 8 ... 阅读全文
posted @ 2015-03-15 19:42 David_W 阅读(145) 评论(0) 推荐(0)
摘要: //代码来源:http://discuss.leetcode.com/questions/29/spiral-matrix。 class Solution { public: vector spiralOrder(vector >& matrix) { ... 阅读全文
posted @ 2015-03-15 19:39 David_W 阅读(184) 评论(0) 推荐(0)
摘要: 作为快速排序的扩展应用,这里介绍一个选择第k个最小元素的问题。1. 问题描述给定线性序列中的n个元素和一个整数k, 0= key) --last; 9 int_array[first] = int_array[last];10 while(first < last &... 阅读全文
posted @ 2015-03-15 18:06 David_W 阅读(699) 评论(0) 推荐(0)
摘要: 快速排序也是根据分治策略设计的一种高效率的分类算法。首先回顾下分类算法的分类思想:它从待分类序列S中随机取出一个元素x,并把S分成三个子序列S1,S2和S3,分别是S中小于,等于和大于x的元素序列,而后对S1和S2递归使用本算法,就可以得到排好序的序列。实际操作中通常不分出序列S2,而是直接把S2中... 阅读全文
posted @ 2015-03-15 16:45 David_W 阅读(167) 评论(0) 推荐(0)
摘要: 合并排序算法的时间复杂度为O(nlogn), 是渐近意义下的最优算法。合并算法也是分治算法的应用例子。合并算法的基本思想:将待排序元素分成大小大致相等的2个子集合,分别对这2个子集合进行排序,最后将排好序的子集合合并成为所要求的排好序的集合。算法实现: 1 template 2 void merge... 阅读全文
posted @ 2015-03-15 16:24 David_W 阅读(362) 评论(0) 推荐(0)
摘要: 作为分治法的典型应用,二分搜索是程序员的常用算法。但是这个算法,却往往容易写错。因此,特意备份了July的一份代码,以备查询之用。//二分查找V0.1实现版 //copyright@2011 July //随时欢迎读者找bug,email:zhoulei0907@yahoo.cn。 //首... 阅读全文
posted @ 2015-03-15 16:01 David_W 阅读(158) 评论(0) 推荐(0)
摘要: 本文探讨了游戏AI中一种实现技术. 阅读全文
posted @ 2015-03-11 16:36 David_W 阅读(293) 评论(0) 推荐(0)