The Challenge Program Design Competition 2.4 data structures for processing and storage

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.