关于ACM竞赛的相关tips

1、vector sort 的降序

vector<int> v;
// 其sort降序
bool cmp(int a,int b){
    return a>b;
}
sort(v.begin(),v.end(),cmp);

//去重
sort(vt.begin(),vt.end());
vt.erase(unique(vt.begin(),vt.end()),vt.end());

2、priority_queue + struct 的排序

struct edge{
    int a,b,c;
}e[3];
class cmp{
    public:
        bool operator()(edge &a,edge &b){
            return a.c>b.c;
        }
};
int main(){
    e[0].c = 1;
    e[1].c = 2;
    e[2].c = 4;
    priority_queue<edge,vector<edge>,cmp> Q;
    Q.push(e[0]);
    Q.push(e[1]);
    Q.push(e[2]);
    auto t = Q.top();
    cout<<t.c<<endl;
    return 0;
}

输出:1

3、long long 大小的位运算时记得 1LL<<n or 1ll<<n

  否则会溢出,尽管n是long long的!!!

 

posted @ 2021-10-04 22:04  wanghai673  阅读(41)  评论(0)    收藏  举报