原创 堆排序

//因爲邊界問題調試了一天半,權當是教訓吧 #include<iostream> #include<algorithm> using namespace std; #define N 10 void HeapAdjust(int arr[

原创 全排列的遞歸算法(以此加深對遞歸的理解)

#include<iostream> #include<algorithm> using namespace std; #define length 3 void permutation(char arr[],int idx,int si

原创 斐波那契數

//遞歸 #include<iostream> using namespace std; int fun(int idx) { if(idx<=2) return 1; else return fun(idx-1)+fun(i

原创 POJ2140

#include<iostream> #include<cmath> using namespace std; double Q(double m,double n) { double q=0.5-(m/2)+(n/m); retur

原创 POJ2015

//POJ2105#include<iostream> #include<string> #include<vector> using namespace std; int Q(int x) { int n=1; for(int s=

原创 DFS 的遞歸做法

#include<iostream>//得到搜索路徑 using namespace std; #define N 9 bool visit[N]; void dfs(bool arr[N][N],int i) { visit[i]=t

原创 POJ3664

//知道爲什麼幾次提交都是WA了,原來是struct沒有初始化,對於任何程序,細節決定成敗 #include<iostream> #include<algorithm> using namespace std; #define SIZE

原创 Twisted源碼分析1

Twisted是用python編寫的事件驅動的網絡框架,雖然Twisted從發佈到現在已經有不少年頭了,而且現在也出現了不少新的高性能異步I/O框架,比如說tornado,但是Twisted任然具有很好的學習價值。如果想要看Twisted

原创 poj1321棋盤問題

#include <iostream> //#include <vector> using namespace std; const int MAX = 9; int account = 0; bool visit_col[MAX];/

原创 Twisted源碼分析3

在前兩節中,我們通過一個簡單的例子從服務器端的角度簡要的研究了twisted的源碼。在本節,我們將通過另外一個例子,從客戶端的角度研究twisted的相關源碼,完整例子在這裏 下面是簡化的代碼: class PoetryProtocol(

原创 二叉搜索樹

# -*- encoding:utf8 -*- # 二叉搜索樹 class TreeNode(object): def __init__(self, key): self._key = key self._left = None

原创 Twisted源碼分析2

在上一篇博文中,我們借一個小例子簡要講解了創建事件監聽循環,與客戶端建立連接。這次,我們將繼續按照上一篇開頭的例子來探究負責底層傳輸的transport類 # /twisted/internet/tcp.py def doRead(se

原创 POJ1731

<pre name="code" class="cpp">#include <iostream> #include <algorithm> #include <string> using namespace std; int func(s

原创 AVL樹

# -*- encoding:utf8 -*- # ### 平衡二叉樹 ### import BinarySortTree class Node(BinarySortTree.TreeNode): def __init__(self

原创 堆排序 python

# -*- encoding:utf8 -*- def heapsort(alist): # 保持最大堆 def max_heapify(alist, idx, size): left = idx * 2 + 1 right