算法竞赛入门经典第五章习题

先写一点我认为重要的
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


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值