语法复键之Lambda排序、priority_queue、multiset / set、动态开二维vector
本文搬运自本人高中时期CSDN博客,若图片加载不出来,可到原文查看:https://blog.csdn.net/zhangtingxiqwq/article/details/162002963
使用Lambda实现sort排序
1
| sort(a + 1, a + n + 1, [] (node &x, node &y) {return x.v > y.v; });
|
Priority_queue
1 2 3 4
| priority_queue<int, vector<int>, greater<int> >q; q.push(x); y = q.top(); q.pop();
|
动态开二维vector
1
| vector<vector<int>> a(n + 10, vector<int>(m + 10, 0));
|
multiset / set
1 2 3 4 5 6 7 8 9 10 11
| multiset<int>s; s.insert(5); s.erase(5); auto it = s.find(5); if(it != s.end()) s.erase(it); s.count(5); auto itl = s.lower_bound(5); auto it2 = s.upper_bound(5); s.clear(); s.size();
|