This chapter introduces several data structures: heap, binary search tree, and check set.
The first part of the heap.
The implementation of the heap:
intHEAP[MAXN];voidPushintx) { inti = sz;//the number of your own node. while(I >0) { intp = (I-1) /2; if(Heap[p] <= x) Break; Heap[i]=Heap[p]; I=p; } Heap[i]=x;} intpop () {intRET = heap[0];//Remove the element with the highest priority intx = Heap[--sz];// inti =0; whileI2+1<SZ) { intA = i *2+1, B = i *2+2; if(b < sz && heap[b] < heap[a]) A =b; //If there are 2 sons, then choose the smaller son (the son is smaller than himself) to Exchange if(Heap[a] >= x) Break;//exit without order reversalHeap[i] =Heap[a]; I=A; } Heap[i]=x; returnret;}
Normally we use priority queues in STL libraries to solve problems.
Example: Poj 2431 Expedition
POJ 3614 Sunscreen
POJ Moo university-financial Aid
POJ 2236 Wireless Network
POJ 1703 Find Them,catch them
The Challenge Program Design Competition 2.4 data structures for processing and storage