zoukankan      html  css  js  c++  java
  • hdu 1908 double queues

    http://acm.hdu.edu.cn/showproblem.php?pid=1908

    看到有两个优先级,然后题目中又有queue。。。就想到了优先队列。。。

    但是优先队列的cmp函数没搞懂,因为比较的是结构体,好像要重载< 什么的。

    然而并不会。

    其实用map就可以做。。。

    map在插入的时候可以自动按关键字排序,简直好评如潮!

    #include <algorithm>
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <map>
    #include <stack>
    #include <queue>
    
    using namespace std;
    typedef long long LL;
    const int inf = 8E8;
    
    
    
    int cmd;
    map<int,int>a;
    int p,k;
    
    int main()
    {
    
        while (scanf("%d",&cmd)!=EOF&&cmd)
        {
           if (cmd==1)
           {
               scanf("%d %d",&k,&p);
               a[p]=k;
           }
           if (cmd==2)
           {
               if (a.empty())
               {
                   cout<<"0"<<endl;
               }
               else
               {
                   cout<<a.rbegin()->second<<endl;
                   a.erase(a.find(a.rbegin()->first));
               }
           }
           if ( cmd==3 )
           {
               if (a.empty())
               {
                   cout<<"0"<<endl;
               }
               else
               {
                   cout<<a.begin()->second<<endl;
                   a.erase(a.begin());
               }
           }
        }
    
        return 0;
    }
  • 相关阅读:
    Fleury算法
    2012 MultiUniversity Training Contest 2
    高斯若尔当消元法(线性代数)
    hdu4307(最小割)
    hdu4305(生成树计数)
    hdu4318(最短路)
    hdu4309(网络流)
    hdu4313(生成树)
    生成树计数
    MYSQL 远程登录及常用命令
  • 原文地址:https://www.cnblogs.com/111qqz/p/4618278.html
Copyright © 2011-2022 走看看