PKU3481 (Double Queue) STL-map

Source: Internet
Author: User

[Cpp]/********************************** * ***** question: code = 1 then k is in the queue, and k has a priority of p; code = 2: Process columns with the highest priority; code = 3: Process columns with the lowest priority; algorithm idea: Use map in STL for processing, because map can be automatically sorted; Use priority p as the map keyword; each inserted element map will be automatically sorted; output as required; **************************************** **/# include <iostream> # include <algorithm> # include <stack> # include <cstring> # include <cstdlib> # include <cstdio> # include <map> using namespace std; int main (){// Freopen ("C :\\ Users \ Administrator \ Desktop \ kd.txt", "r", stdin); int code; map <int, int> Map; while (scanf ("% d", & code) {if (code = 1) {int k, p; scanf ("% d ", & k, & p); Map [p] = k;} else if (code = 3) {if (! Map. empty () {printf ("% d \ n", Map. begin ()-> second); Map. erase (Map. begin (); // Delete the first element of the queue in the order} else puts ("0");} else {if (! Map. empty () {www.2cto.com printf ("% d \ n", Map. rbegin ()-> second); Map. erase (Map. find (Map. rbegin ()-> first); // Delete the first element of the reverse queue. Note the difference between this element and the deleted ordered queue.} else puts ("0") ;}} return 0 ;}

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.