代码之家  ›  专栏  ›  技术社区  ›  asn

按降序保持对对的集合[复制]

  •  0
  • asn  · 技术社区  · 7 年前

    set<pair<ll,pair<ll,ll> > > st 按以下逻辑降序排列:

    bool comp(pair<ll,pair<ll,ll> > a, pair<ll,pair<ll,ll> > b){
        if(a.first!=b.first)
            return a.first > b.first;
        return a.second.first > b.second.first;
    }
    

    set<pair<ll,pair<ll,ll> > , comp> st;

    它给出以下错误:

    error: template argument for template type parameter must be a type

    通常在对向量排序时,我们会: sort(v.begin(),v.end(),comp) pair<ll,pair<ll,ll> >

    这两种情况有什么不同,我应该如何正确地执行逻辑?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Fureeish    7 年前

    而不是定义 comp struct comp 具有 operator()

    struct comp{
        bool operator () (pair<ll,pair<ll,ll> > a, pair<ll,pair<ll,ll> > b) const {
            if(a.first!=b.first)
                return a.first > b.first;
            return a.second.first > b.second.first;
        }
    }