zoukankan      html  css  js  c++  java
  • priority_queue custom compare(cmp)

    #include <bits/stdc++.h>
    //#define endl '
    '
    #define lose {printf("NO
    ");return;}
    #define win {printf("YES
    ");return;}
    #define all(A) (A).begin(),(A).end()
    #define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
    #define PER(I, A, B) for (int I = (A); I >= (B); --I)
    #define DB(A) cout<<(A)<<endl 
    #define lson k*2
    #define rson k*2+1
    #define fi first
    #define se second
    #define PB push_back
    #define Pair pair<int,int>
    #define MP make_pair
    #define LL long long
    #define ull unsigned long long
    //#define int LL
    using namespace std;
    #define DB1(args...) do { cout << #args << " : "; dbg(args); } while (0)
    void dbg() { std::cout << "  #
    "; }
    template<typename T, typename...Args>
    void dbg(T a, Args...args) { std::cout << a << ' '; dbg(args...); }
    //var
    const int maxn=2e5+10;
    const int MAX=1000;
    const int inf=0x3f3f3f3f;   
    const int mod=1e9+7;
    //head
    int n,m;
    int w[maxn]; 
    int d[maxn];
    int last[maxn];
    
    
    
    
    void solve()
    {
    
    	last[1]=1;
    	last[2]=2;
    	auto cmp = [](int a, int b) { return last[a] > last[b]; };//who bigger who first
    	priority_queue<int,vector<int>, decltype(cmp)> q(cmp);
    	q.push(1);
    	q.push(2);
    	DB1(q.top());
    	q.pop();
    	DB1(q.top());
    	q.pop();
    	//but it turns out that they left the big number behind( greater )
     
    	
    	
    
    	
    } 
    signed main()
    {
        // freopen("read.txt", "r", stdin);
        // freopen("ans.txt", "w", stdout);
        int TestCase = 1;
        //cin>>TestCase;
        while (TestCase--)
        {
            solve();
        }
        char EndFile = getchar();
        EndFile = getchar();
        return 0;
    }
    
    
  • 相关阅读:
    模板合集
    1201: 众数问题
    112. 路径总和
    Hibernate的配置及CURD
    5. 最长回文子串
    1120: 最值交换
    1119: 一维数组排序
    1118: 数列有序
    1117: 查找数组元素
    1116: 删除元素
  • 原文地址:https://www.cnblogs.com/reshuffle/p/13860808.html
Copyright © 2011-2022 走看看