随笔分类 -  STL学习

STL中的set使用方法详细!!!!
摘要:1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构操作。vector封装数组,list封装了链表,map和set封装了二叉树等,在封装这些数据结构的时 阅读全文
posted @ 2018-11-22 16:35 知识天地 阅读(1933) 评论(0) 推荐(0) 编辑
codeforces上一道贪心算法题
摘要:http://codeforces.com/contest/218/problem/B贪心算法:STL优先队列实现最大堆,最小堆#include<iostream>#include<queue> using namespace std;const int MAX=1001;int a[MAX];int calPrize(int n, int x){ int start=n-x+1; return (start+n)*x/2;} int fun(int n, int m, int pos[]){ priority_queue<int,vector<int> 阅读全文
posted @ 2012-09-19 14:25 知识天地 阅读(431) 评论(0) 推荐(0) 编辑
priority_queue 用法总结
摘要:今天在写堆和哈夫曼树的ACM题的时候,接触到priority_queue的用法,由于比较函数的难些,请教过队内的红薯和杨大牛后才稍微弄明白些,下面总结如下,首先我是用手写的堆来过题的,其实和照黑书指导上的那个堆的代码差不多。 写完之后就看了下STL里面的priority_queue的用法就开始研究,首先是用了网上找的一个写比较函数的方法是用操作符重载做的。代码如下://比较函数对于结构体struct heapmin{heapmin(int tx){x=tx;};int x;};struct heapmax{heapmax(int tx){x=tx;};int x;};bool operator 阅读全文
posted @ 2012-09-19 07:25 知识天地 阅读(1705) 评论(0) 推荐(0) 编辑
优先队列实现n路归并算法O(n * lgK)
摘要://problem description: merge K sorted lists with total N elements//solution: put the front element of each list into a priority queue,// till finish, pop the min value from the priority queue, and enqueue// the next element in corresponding list, delete that element//time complexity:// ... 阅读全文
posted @ 2012-09-09 18:59 知识天地 阅读(523) 评论(0) 推荐(0) 编辑
STL之二分查找 (Binary search in STL)
摘要:Section I正确区分不同的查找算法count,find,binary_search,lower_bound,upper_bound,equal_range本文是对Effective STL第45条的一个总结,阐述了各种查找算法的异同以及使用他们的时机。首先可供查找的算法大致有count,find,binary_search,lower_bound,upper_bound,equal_range。带有判别式的如count_if,find_if或者binary_search的派别式版本,其用法大致相同,不影响选择,所以不作考虑。注意这些查找算法需要序列式容器,或者数组。关联容器有相应的同名成 阅读全文
posted @ 2012-09-05 23:33 知识天地 阅读(10458) 评论(0) 推荐(2) 编辑