zoukankan      html  css  js  c++  java
  • queue

      1 #include <iostream>
      2 #include <cstdio>
      3 #include <cstring>
      4 #include <string>
      5 #include <utility>
      6 #include <algorithm>
      7 #include <vector>
      8 #include <queue>
      9 #include <stack>
     10 #include <cmath>
     11 #include <set>
     12 #include <map>
     13 using namespace std;
     14 #define max(x,y) x>=y?x:y
     15 #define lowbit(x) x&(-x)
     16 typedef  long long ll;
     17 using namespace std;
     18 int main()
     19 {
     20     priority_queue<int>q1;
     21     priority_queue<int,vector<int>,greater<int> >q2;//top最小
     22     for (int i=1;i<=5;i++)
     23     {
     24         q1.push(i);
     25         q2.push(i);
     26     }
     27     while(!q1.empty())
     28     {
     29         cout<<q1.top()<<endl;
     30         q1.pop();
     31     }
     32     cout<<"
    
    
    ";
     33     while(!q2.empty())
     34     {
     35         cout<<q2.top()<<endl;
     36         q2.pop();
     37     }
     38     return 0;
     39     
     40     /*
     41     5
     42 4
     43 3
     44 2
     45 1
     46 
     47 
     48 
     49 1
     50 2
     51 3
     52 4
     53 5
     54 */
     55 
     56 
     57 #include  <iostream>
     58 #include <cstdio>
     59 #include <cstring>
     60 #include <queue>
     61 using namespace std;
     62 /*
     63 struct Node{
     64     int w,id;
     65     Node(){}
     66     Node(int w,int id):w(w),id(id){}
     67     bool operator <(const Node &a)const{
     68         if(w==a.w)
     69             return id<a.id;
     70         return w<a.w;
     71     }
     72     
     73 1 2 2 3 3
     74 
     75 
     76 3 5
     77 3 4
     78 2 3
     79 2 2
     80 1 1
     81 };
     82 */
     83 struct Node{
     84     int w,id;
     85     Node(){}
     86     Node(int w,int id):w(w),id(id){}
     87     bool operator <(const Node &a)const{
     88         if(w==a.w)
     89             return id>a.id;
     90         return w>a.w;
     91     }
     92     /*
     93 1 2 2 3 3
     94 
     95 
     96 1 1
     97 2 2
     98 2 3
     99 3 4
    100 3 5
    101 */
    102 
    103 };
    104 int main()
    105 {
    106     priority_queue<Node>q;
    107     int x;
    108     for(int i=1;i<=5;i++)
    109     {
    110         scanf("%d",&x);
    111         q.push(Node(x,i));
    112     }
    113     
    114     while(!q.empty()){
    115         Node tmp=q.top();
    116         q.pop();
    117         printf("%d %d
    ",tmp.w,tmp.id);
    118     }
    119     return 0;
    120 }

    priority_queue<P,vector<P>,greater<P> >Q;
    for(int i=0;i<n;i++){
    scanf("%lld%lld",&x,&y);
    Q.push(P(x,y));
    }
    while(!Q.empty()){
    P p = Q.top();
    ll x= p.first;
    ll y = p.second;
    Q.pop();
    printf("%lld %lld ",x,y);
    }
    1 5
    2 4
    1 6
    1 5
    1 6
    2 4

    #include <bits/stdc++.h>
    using namespace std;
    struct Node{
        int x,y;
        friend bool operator< (Node a, Node b)
        {
            return a.x < b.x;
        }
        Node();
        Node(int x,int y):x(x),y(y){
        }
    };
    priority_queue<Node>q;
    int x,y;
    int main()
    {
        for(int i =0;i<4;i++){
            scanf("%d %d",&x,&y);
            q.push(Node(x,y));
        }
        while(!q.empty()){
            Node tmp  =q.top();
            q.pop();
            printf("%d %d
    ",tmp.x,tmp.y);
        }
        return 0;
    }
    
    
    1 1
    2 2
    3 3
    4 4


    4 4 3 3 2 2 1 1
    #include  <iostream>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <algorithm>
    using namespace std;
    const int N=10;
    int a[N];
    bool cmp(int x,int y){
        return x<y;
    }
    int main()
    {
        for(int i =1;i<=5;i++) a[i-1]=i;
        sort(a,a+5,cmp);
        for(int i =0;i<5;i++) {
            printf("%d
    ",a[i]);
            
        }
    1
    2
    3
    4
    5
        return 0;
    }
  • 相关阅读:
    顺序栈--Java实现
    优先队列(存储结构数组)--Java实现
    队列(存储结构数组)--Java实现
    有序链表--Java实现
    双向链表--Java实现
    表达式求值--Java实现
    【Mac + Appium】之运行报错:[UiAutomator] UiAutomator exited unexpectedly with code 0, signal null
    【Mac + ATX基于uiautomator2】使用weditor时,报错:requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
    【Mac系统 + Python + Django】之开发一个发布会系统【Django模型(三)】
    【转】【Mac系统】之ADB命令总结
  • 原文地址:https://www.cnblogs.com/tingtin/p/10518874.html
Copyright © 2011-2022 走看看