摘要: 等价关系:自反性,对称性,传递性class DisjSets//不相交集的类架构{public: explicit DisjSets(int numElements); int find(int x) const; int find(int x); void unionSets(int root1,int root2); void unionSets2(int root1,int root2);private: vector<int> s;};DisjSets::DisjSets(int numElements) : s(numElements)//初始化{... 阅读全文
posted @ 2012-10-07 14:18 xingoo 阅读(606) 评论(0) 推荐(0) 编辑
摘要: Tick and TickTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5553 Accepted Submission(s): 1518Problem DescriptionThe three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of th... 阅读全文
posted @ 2012-10-06 23:30 xingoo 阅读(546) 评论(1) 推荐(0) 编辑
摘要: 平均时间O(NlogN),最坏O(N^2)主要过程四步:1 如果S中元素为1 或者 0 ,直接返回2 取S中的任一元素v,称为 枢纽元3 将集合按照 枢纽元大小 分成两个集合4 两个子集合递归调用2 - 3选取枢纽元方法:1错误方法:直接选取第一个2安全方法: 随即选取一个枢纽元3三数中值分割法:选取数组的中值主要代码: 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 template <typename Comparable> 5 void quicksort( vect 阅读全文
posted @ 2012-09-27 20:53 xingoo 阅读(513) 评论(0) 推荐(0) 编辑
摘要: 采用分治的思想 以O(NlogN)最坏的情形运行时间运行如果对merge的每个递归调用都采用局部声明一个临时数组,那么在任一时刻就可能有logN个临时数组处在活动期代码如下: 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 template <typename Comparable> 5 void mergeSort(vector<Comparable> & a) 6 { 7 vector<Comparable> tmpArray(a.siz 阅读全文
posted @ 2012-09-27 19:34 xingoo 阅读(334) 评论(0) 推荐(0) 编辑
摘要: 说白了,也就是大堆,或者小堆,通过删掉堆顶点,然后存入数组,来实现排序:第一阶段:构建堆最多用2N次比较第二阶段:第i次deleteMax最多用到2【logi】次比较,总数最多2NlogN-O(N)次比较代码: 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 template <typename Comparable> 5 void heapsort(vector<Comparable> & a) 6 { 7 for(int i = a.size()/2 阅读全文
posted @ 2012-09-27 16:18 xingoo 阅读(305) 评论(0) 推荐(0) 编辑
摘要: 使用希尔增量时排序的最坏为:O(n^2);代码如下: 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 template <typename Comparable> 5 void shellsort(vector<Comparable> & a) 6 { 7 for(int gap = a.size()/2; gap > 0; gap /= 2) 8 for(int i = gap; i < a.size() ; i++) 9 {10 Comp 阅读全文
posted @ 2012-09-27 15:20 xingoo 阅读(315) 评论(0) 推荐(0) 编辑
摘要: 程序代码: 1 #include "../common/InitSock.h" 2 #include <stdio.h> 3 CInitSock initSock; 4 void main() 5 { 6 char szHost[256]; 7 ::gethostname(szHost,256); 8 hostent *pHost = ::gethostbyname(szHost); 9 in_addr addr;10 for(int i =0;;i++)11 {12 char *p = pHost->h_addr_list[i]... 阅读全文
posted @ 2012-09-25 23:31 xingoo 阅读(416) 评论(1) 推荐(0) 编辑
摘要: winsock第一个版本使用sockaddr来强迫使用特定的寻址方式,这样添加其他的协议就不可能了1 struct sockaddr2 {3 u_short sa_family;//地址家族4 char sa_data[14];//不同的地址家族,不同5 };在winscok中 应用程序通过SOCKADDR_IN结构来指定IP地址和端口号1 struct scockaddr_in{2 short sin_family;//地址家族3 u_short sin_port;//端口号4 struct in_addr sin_addr;//IP地址5 c... 阅读全文
posted @ 2012-09-25 23:11 xingoo 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 最简单的排序算法了,每一次j--到对应的值,不会减到0,这个纠结我好久 1 #include "stdafx.h" 2 #include <iostream> 3 #include <vector> 4 using namespace std; 5 6 template <typename Comparable> 7 void insertionSort(vector<Comparable> & a) 8 { 9 int j;10 for(int p=1 ; p<a.size() ; p++)11 {12 Com 阅读全文
posted @ 2012-09-25 21:16 xingoo 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 1 不能遇到问题想办法逃避,要想明白这个问题为什么出现,如何避免2 不能遇到问题总寄托于别人,想让别人来帮你解决3 可以跟别人沟通自己的想法,但是自己没有主见4 代码终究只是代码,大不了回滚,不要畏惧.5 测试要用心,遇到问题不能能过且过.6 不能对代码产生恐惧感,先看函数,再看变量,最后分析一下执行顺序,没什么大不了这两天学了很多东西:1 不要完事求方法2 chrome的断电测试方法3 快速查看函数执行顺序4 变量调用方法规则5 轻微JS思想 阅读全文
posted @ 2012-09-25 21:11 xingoo 阅读(574) 评论(0) 推荐(1) 编辑