先写一点我认为重要的
Priority_queue set map 等使用struct类型时,必须重载<号。
定义模板如下:
struct node
{
int a,b;
node(int x = 0,int y = 0):a(x),b(y){}
bool operator<(const node& rhs) const
{
if ( a == rhs.a ) return b > rhs.b; //b越小优先级越高
else return a < rhs.a; //a越大优先级越高
}
};
Proirity_queue
1、优先队列默认数越大,优先级越高,是大根堆
2、若想维护小根堆,priority_queue< int , vector<int> , greater<int> > q
3、优先队列使用 struct 重载<
Set
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
Set_union( ALL(x1) , ALL(x2) , INS(x) ); vector x为 x1和x2的并集
Set_intersection( ALL(x1) , ALL(x2) , INS(x) ); vector x为 x1和x2的交集
Deque
c.front()返回c容器的第一个元素
c.push_front(num)在开头位置插入元素
c.pop_front()删除开头位置的元素
c.back()返回c容器的最后一个元素
c.push_back(num)在末尾位置插入元素
c.pop_back()删除末尾位置的元素
习题 5-1:http://blog.csdn.net/chy20142109/article/details/50650966
习题 5-2:http://blog.csdn.net/chy20142109/article/details/50650968
习题 5-3:http://blog.csdn.net/chy20142109/article/details/50650970
习题 5-4:http://blog.csdn.net/chy20142109/article/details/50650972
习题 5-5:http://blog.csdn.net/chy20142109/article/details/50650973
习题 5-6:http://blog.csdn.net/chy20142109/article/details/50650974
习题 5-7:http://blog.csdn.net/chy20142109/article/details/50650977
习题 5-8:http://blog.csdn.net/chy20142109/article/details/50650980
习题 5-9:http://blog.csdn.net/chy20142109/article/details/50650981
习题 5-15:http://blog.csdn.net/chy20142109/article/details/50754545