zoukankan      html  css  js  c++  java
  • 模板

    #include<stdio.h>
    #include<algorithm>
    #include<queue>
     
    using namespace std;
     
    struct node{
        int num;
        node(int i){
            num = i;
        }
    };
     
    priority_queue<node>key;
     
    bool operator <(node a ,node b){
        return a.num<b.num;
    }
     
     
    int main(){
        key.push(node(1));
        key.push(node(4));
        printf("%d ",key.top().num);
        key.pop();
        key.push(node(2));
        key.push(node(3));
        printf("%d ",key.top().num);
    }
     
     
     
    =============================================================================
    struct compare {
        bool operator()(const ListNode* l, const ListNode* r) {
            return l->val > r->val;
        }
    };
    ListNode *mergeKLists(vector<ListNode *> &lists) { //priority_queue
        priority_queue<ListNode *, vector<ListNode *>, compare> q;
        for(auto l : lists) {
            if(l)  q.push(l);
        }
        if(q.empty())  return NULL;

        ListNode* result = q.top();
        q.pop();
        if(result->next) q.push(result->next);
        ListNode* tail = result;           
        while(!q.empty()) {
            tail->next = q.top();
            q.pop();
            tail = tail->next;
            if(tail->next) q.push(tail->next);
        }
        return result;
    }
     
     
     
  • 相关阅读:
    最优贸易 NOIP 2009 提高组 第三题
    Think twice, code once.
    luogu P1378 油滴扩展
    codevs 1002 搭桥
    codevs 1014 装箱问题 2001年NOIP全国联赛普及组
    洛谷P2782 友好城市
    洛谷P1113 杂务
    [HDU1848]Fibonacci again and again
    [POJ2420]A Star not a Tree?
    [SCOI2010]生成字符串
  • 原文地址:https://www.cnblogs.com/clover-xuqi/p/7182289.html
Copyright © 2011-2022 走看看