X周

导航

2013年9月3日 #

各种难题解惑

摘要: 各类难题解答 阅读全文

posted @ 2013-09-03 21:08 X周 阅读(355) 评论(0) 推荐(0)

2013年6月24日 #

求逆序数算法

摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 7 int Inversion(int a[],int start,int mid,int end){ 8 9 int PairNum = 0;10 11 for(int i=start;ia[j])16 ++PairNum;17 } 18 }19 20 return PairNum;21 }22 int Inversion1(int a[],int... 阅读全文

posted @ 2013-06-24 21:16 X周 阅读(621) 评论(0) 推荐(0)

2013年6月23日 #

堆、快速排序实现

摘要: 比较排序:在排序的最终结果中,各元素的次序依赖于它们之间的比较结果。 1 #include 2 #include 3 #include 4 5 using namespace std; 6 void exchange(int &a,int &b){ 7 8 int temp; 9 temp = a; 10 a = b; 11 b=temp; 12 cout"key) 42 --j; 43 if(ia[largest]) 67 large... 阅读全文

posted @ 2013-06-23 16:06 X周 阅读(263) 评论(0) 推荐(0)

2013年6月19日 #

求数组的最大子数组

摘要: 求数组的最大和子数组是经典问题,许多书籍都提到,比如算法导论,编程珠玑。更是覆盖很多面试书,比如编程之美,剑指Offer等。以下是我关于该问题的理解与实现。 1 #include<iostream> 2 #include<cstdlib> 3 #include<climits> 4 using namespace std; 5 6 class SubArray{ 7 private: 8 int left; 9 int right; 10 int sum; 11 public: 12 void set(int l,int r,int s... 阅读全文

posted @ 2013-06-19 17:17 X周 阅读(240) 评论(0) 推荐(0)

2013年6月6日 #

LazyMapReduce

摘要: 两种LazyMapReduce实现方法对比: 1 import org.apache.hadoop.conf.Configuration; 2 import org.apache.hadoop.util.GenericOptionsParser; 3 import org.apache.hadoop.mapreduce.Job; 4 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 5 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 6 im 阅读全文

posted @ 2013-06-06 14:45 X周 阅读(215) 评论(0) 推荐(0)

2013年5月16日 #

折半查找实现1

摘要: 1 /* binarySearch 2 05/05/13 17:24 3 */ 4 #include<iostream> 5 #include<cstdlib> 6 using namespace std; 7 int binarySearch(int *array,int low,int high,int value)// 返回value的位置,如果是-1则表示没找到 8 { 9 if(low<=high){10 int mid;11 mid= (low+high)/2;12 if(value==array[mid])13 ... 阅读全文

posted @ 2013-05-16 21:34 X周 阅读(180) 评论(0) 推荐(0)

2013年5月13日 #

插入排序

摘要: /*insertion sort26/04/13 20:15*/#include<iostream>#include<cstring> using namespace std;int array[1000];void insertsort(int a[],int len){ int i,j,key; for(i=1;i<len;i++){ //已知array[0..i-1]已排序,将A[i]插入使得A[0..i]成为新的已排序数组 key=array[i]; for(j=i-1;j>=0;j--){ if(ke... 阅读全文

posted @ 2013-05-13 08:32 X周 阅读(159) 评论(0) 推荐(0)

归并排序-分治法

摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 /* 7 函数名:Merge 8 功能: 合并有序子序列a[low..mid],a[mid+1..high]为一个有序序列 9 */ 10 void Merge(int a[],int low,int mid,int high){ 11 int sub1_len=mid-low+1; // 计算子序列1的长度 12 int sub2_len=high-mid; ... 阅读全文

posted @ 2013-05-13 08:31 X周 阅读(106) 评论(0) 推荐(0)

2013年去哪网实习笔试题

摘要: 【题目】有一个文件存储了一个酒店业主对其酒店标准间的报价,数据是按行存储,每行的数据表示一个日期段内的价格。格式如下:2013-09-01~2013-11-01 200这行数据表示2013-09-01到2013-11-01这个时间段内的价格都是200请写程序,读取文件中的数据,生成合并好的日期段价格数据按照起始日期升序排序好,输出到另外一个文件(output.txt)合并的规则如下:日期相同的价格以后面的为准相邻日期、价格相同的数据需要合并日期例如2013-09-01~2013-10-31 2002013-10-01~2013-10-07 5002013-11-01~2013-12-31 20 阅读全文

posted @ 2013-05-13 08:28 X周 阅读(654) 评论(0) 推荐(0)