2012年6月20日

对半搜索

摘要: #include <iostream>using namespace std;int a[5]={1,2,3,4,5};int Bsearch(int x, int left,int right ){ if(left<=right) { int m=(left+right)/2; if(x<a[m]) return Bsearch(x,left,m-1); else if (x>a[m]) return Bsearch(x,m+1,right); else return m; } else return -1;}int main(){ int m=Bsearch( 阅读全文

posted @ 2012-06-20 18:13 矮人狙击手! 阅读(210) 评论(0) 推荐(0) 编辑

分治法求最大最小元问题

摘要: 转自:http://www.cnblogs.com/tomctx/archive/2012/04/07/2435887.html(这个人的其他东西也可以参考下,分治,动态规划很好)#include <stdio.h>#include<stdlib.h>int max(int a, int b){ return (a > b) ? a : b;}int min(int a, int b){ return (a < b) ? a : b;}void maxmin(int A[], int &e_max, int &e_min ,int low, 阅读全文

posted @ 2012-06-20 17:23 矮人狙击手! 阅读(949) 评论(0) 推荐(0) 编辑

导航