锘??xml version="1.0" encoding="utf-8" standalone="yes"?>色成年激情久久综合,www.久久热.com,日本精品久久久久中文字幕http://www.shnenglu.com/NicYun/category/9721.html鍩虹鐭ヨ瘑瀛︿範zh-cnFri, 13 Mar 2009 04:15:48 GMTFri, 13 Mar 2009 04:15:48 GMT60鏍戠姸鏁扮粍http://www.shnenglu.com/NicYun/archive/2009/03/13/76415.htmlNicYunNicYunFri, 13 Mar 2009 03:30:00 GMThttp://www.shnenglu.com/NicYun/archive/2009/03/13/76415.htmlhttp://www.shnenglu.com/NicYun/comments/76415.htmlhttp://www.shnenglu.com/NicYun/archive/2009/03/13/76415.html#Feedback0http://www.shnenglu.com/NicYun/comments/commentRss/76415.htmlhttp://www.shnenglu.com/NicYun/services/trackbacks/76415.htmlclass TreeArray { int c[1100000]; // element id must start at 1 int size; int lowbit(int x) { return x & (-x); } public: void init(int s = N -1) { size = s; memset(c,0,size *sizeof(c[0])); } int sum(int n) // 鍓峮涓暟鐨勫拰錛屽寘鎷琻 { int s =0; while (n >0) { s += c[n]; n -= lowbit(n); } return s; } void plus(int p,int x) // add x to the element at position p { while (p <= size) { c[p] += x; p += lowbit(p); } } };
void swap(int&a,int&b) { int temp = a; a = b; b = temp; }
class Heap { int size; int heap[SIZE]; public: virtualbool cmp(int a,int b) =0; private: inline int fathter(int p) { return p /2; } inline int LeftSon(int p) { int son =2* p; if (son > size) return0; return son; } inline int RightSon(int p) { int son =2* p +1; if (son > size) return0; return son; } int ShiftUp(int p) { if (p ==1) return p; if (cmp(heap[p],heap[fathter(p)])) { swap(heap[p],heap[fathter(p)]); return fathter(p); } return p; } int ShiftDown(int p) { int lagest = p;
if ((LeftSon(p)) && (cmp(heap[LeftSon(p)],heap[lagest]))) lagest = LeftSon(p); if ((RightSon(p)) && (cmp(heap[RightSon(p)],heap[lagest]))) lagest = RightSon(p); if (lagest != p) swap(heap[lagest],heap[p]); return lagest; } public: Heap() { size =0; } int insert(int n); void del(int p); void DelHead(); int head(); void init(); bool IsEempty(); }; int Heap::insert(int n) { size++; heap[size] = n; int where = size; int p; while (((p = ShiftUp(where)) != where)) { where = p; continue; } return where; } void Heap::del(int p) { heap[p] = heap[size]; size--; int where; while (((where = ShiftDown(p)) != p)) { p = where; continue; } } void Heap::DelHead() { del(1); } int Heap::head() { if (size ==0) return-1; return heap[1]; } void Heap::init() { size =0; } bool Heap::IsEempty() { if (size ==0) return1; else return0; }
class MaxHeap : public Heap { bool cmp(int a,int b) { return a > b; } };
class MinHeap : public Heap { bool cmp(int a,int b) { return a < b; } };