随笔分类 -  算法

简单的归并排序
摘要:#include <iostream>using namespace std;int main(){ int a[5]={1,3,5,7,9}; int b[5]={2,4,6,8,10}; int c[11]; int i=0,j=0,k=0; while(i<5 && j<5) { if(a[i]<b[j]) { c[k++]=a[i]; i++; } else { c[k++]=b[j]; j++; } } while(i<5) c[k++]=a[i++]; while(j<5) c[k++]=b[j++]; for(i=0;i& 阅读全文

posted @ 2012-06-21 01:19 矮人狙击手! 阅读(263) 评论(0) 推荐(0)

对半搜索
摘要:#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 矮人狙击手! 阅读(218) 评论(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 矮人狙击手! 阅读(958) 评论(0) 推荐(0)

着色问题
摘要:转自:http://www.cnblogs.com/qinyg/archive/2012/06/19/2543583.html#include<stdio.h>int color[100];//int c[100][100];bool ok(int k ,int c[][100])//判断顶点k的着色是否发生冲突{ int i,j; for(i=1;i<k;i++) if(c[k][i]==1&&color[i]==color[k]) return false; return true;}void graphcolor(int n,... 阅读全文

posted @ 2012-06-19 22:20 矮人狙击手! 阅读(220) 评论(0) 推荐(0)

LRU
摘要:#include <stdio.h> #include <stdlib.h> #define mSIZE 3//分配三个内存页块 #define pSIZE 12//总共12个进程 struct mem{ int num; int count;}memery[3]={0,-1,0,-1,0,-1};static int process[pSIZE] ={1,2,3,4,1,2,5,1,2,3,4,5};//页面访问序列 void LRU(); void get();int main() { get(); printf("\n(LRU)\treplace\n&q 阅读全文

posted @ 2012-06-19 22:18 矮人狙击手! 阅读(237) 评论(0) 推荐(0)

导航