
队列
synapse7
这个作者很懒,什么都没留下…
展开
-
POJ 3629 Card Stacking(队列,两种方法)
Card Stackinghttp://poj.org/problem?id=3629Time Limit: 1000MSMemory Limit: 65536KDescriptionBessie is playing a card game with her N-1 (2 ≤ N ≤ 100) cow friends using a d原创 2013-08-01 10:42:03 · 3519 阅读 · 10 评论 -
POJ 2823 Sliding Window (单调队列)
http://poj.org/problem?id=2823注意G++会TLE。用pair数组模拟deque即可完整代码:/*5360ms,19272KB*/#include#include#includeusing namespace std;const int mx = 1000005;pair minq[mx], maxq[mx]; /// f原创 2014-02-17 14:08:18 · 1576 阅读 · 0 评论 -
POJ 1014 / HDU 1059 Dividing (多重背包&剪枝&单调队列)
http://poj.org/problem?id=1014参考了http://poj.org/showmessage?message_id=173435完整代码: /*0ms,376KB*/#include#includeconst int mx = 7;const int mxw = 1300;int m[mx], dp[mxw], deq[mxw],原创 2014-02-27 18:44:07 · 1045 阅读 · 0 评论 -
POJ 1276 Cash Machine (多重背包&单调队列)
http://poj.org/problem?id=1276模板题。完整代码:/*110ms,4316KB*/#include#includeconst int mx = 1005;const int mxw = 1000005;int w[mx], m[mx], dp[mxw], deq[mxw], deqv[mxw];int solve(int m原创 2014-02-27 14:48:50 · 1771 阅读 · 0 评论 -
C++ STL入门教程(4)——stack(栈),queue(队列),priority_queue(优先队列)的使用(附完整程序代码)
首先,这三者都是顺序容器适配器(适配器(adaptor)是根据原始的容器类型所提供的操作,通过定义新的操作接口,来适应基础的容器类型)。本质上,适配器是使一事物的行为类似于另一事物的行为的一种机制。容器适配器让一种已存在的容器类型采用另一种不同的抽象类型的工作方式实现。例如,假设deq是deque类型的容器,则可以用deq初始化一个新的栈:stack stk(deq);//带容器参数的原创 2013-08-04 22:40:27 · 3671 阅读 · 0 评论 -
POJ 1033 / Northeastern Europe 1998 Defragment (模拟&队列)
Defragmenthttp://poj.org/problem?id=1033Time Limit: 2000MSMemory Limit: 10000KCase Time Limit: 1000MSSpecial JudgeDescriptionYou are taking part in the development原创 2013-08-25 13:09:49 · 1332 阅读 · 2 评论 -
用两个栈实现一个队列——我作为面试官的小结
(PS:可在《算法(第四版)》的1.3.49看到此题)两年前从网上看到一道面试题:用两个栈(Stack)实现一个队列(Queue)。觉得不错,就经常拿来面试,几年下来,做此题的应该有几十人了。通过对面试者的表现和反应,有一些统计和感受,在此做个小结。 用C++描述,题目大致是这样的: 已知下面Stack类及其3个方法Push、Pop和 Count,请用2个Stack实现转载 2014-01-11 10:04:40 · 918 阅读 · 0 评论 -
C++ STL入门教程(3)——deque(双向队列)的使用(附完整程序代码)
一、简介deque(Double Ended Queues,双向队列)和向量很相似,但是它允许在容器头部快速插入和删除(就像在尾部一样)。二、完整程序代码/*请务必运行以下程序对照阅读*/#include #include #include #include using namespace std;void print(int num){ cout << num原创 2013-08-04 22:17:18 · 3135 阅读 · 0 评论 -
UVa 11054/HDU 1489/POJ 2940 Wine trading in Gergovia(贪心&双向队列)
11054 - Wine trading in GergoviaTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1995As you may know from原创 2013-08-05 11:34:57 · 1549 阅读 · 0 评论 -
UVa 11995 I Can Guess the Data Structure! (STL)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3146注意“without error”这句。/*0.038s*/#include#include#includeusing namespace st原创 2014-03-03 20:27:43 · 842 阅读 · 0 评论