
ACM-栈和队列
文章平均质量分 61
LarryNLPIR
专注NLP/IR/Machine Learning/Data Mining
展开
-
POJ 1862 变形虫合成 模拟题 优先权队列
本题很简单,变形虫的长度合成满足一定公式,只要每次从所有变形虫当中取出最长的两只合成新虫放进长度集合即可由于要不断取最大值,可以考虑用优先权队列或者堆Source CodeProblem: 1862 User: yangliuACMerMemory: 272K Time: 47MSLanguage: C++ Resul原创 2011-12-24 21:41:57 · 2665 阅读 · 0 评论 -
LeetCode Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whether原创 2015-07-27 16:38:42 · 3067 阅读 · 0 评论 -
LeetCode Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", which ha原创 2015-03-29 12:47:21 · 1661 阅读 · 0 评论 -
LeetCode Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the原创 2015-03-09 11:39:49 · 1370 阅读 · 0 评论 -
LeetCode Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".思路分析:这题算法很简单,用一个栈就可以搞定。trick part见如下的说明What constitutes a word?A sequence of non原创 2015-01-23 14:30:34 · 1957 阅读 · 0 评论 -
NYU AI作业习题-活动安排问题 BFS+DFS Iterative deepening depth-first search
题目链接 http://cs.nyu.edu/courses/spring12/CSCI-GA.2560-001/prog1.html题目大意:给定n个任务的时间、价值及先后序关系,求一个可行的任务子集,使得时间之和不大于deadline,价值之和不小于targetVaule,且不可出现逆序。算法思路:题目已经给出算法,转化为状态空间搜索问题(tree-structured state原创 2012-02-16 01:28:11 · 4390 阅读 · 0 评论 -
POJ 1521 哈夫曼编码 贪心法
题意:给定字符串,求哈夫曼编码长和它与等长编码的比值,比较基础思路:这题考查哈弗曼编码,但其实没必要建树得出编码,只需要统计哈弗曼编码后的总码长即可参考了网友的题解,用到了优先权队列维持一个从小到大的序列第38行其实就是把越小的频数反复多加几次,越大的频率少加几次,体现了前缀码的设计思想Source CodeProblem: 1521 User:原创 2011-12-29 02:28:51 · 6054 阅读 · 1 评论 -
面试题研究 用两个栈模拟实现队列
这是我面试一个公司的时候碰到的面试题Q 请用两个栈模拟实现队列,至少完成入队、出队及计算长度的方法A 基本思路是两次后进先出 = 先进先出,元素入队列总是入左栈,元素出队列如果右栈不为空直接弹出右栈头元素;如果右栈为空就把左栈元素出栈全部压入右栈,再弹出右栈头,这样就模拟出了一个队列。Class Q{ stack S1,S2; void push(int a){原创 2011-12-21 00:29:31 · 2270 阅读 · 0 评论 -
POJ 1033 磁盘文件碎片整理 模拟题 栈应用
以后一定要细心,不能再犯这个低级的错误,把WA控制在最低范围内参考了 http://www.cnblogs.com/damacheng/archive/2010/09/24/1833983.html的题目分析题目大意:你要写一个OS,要实现磁盘碎片整理的功能。磁盘分为N个簇,一个文件可以占用K个簇,(1 文件1:2 3 11 12,占用了4个簇,编号为1-4。 文件2:7,占原创 2011-12-24 20:33:23 · 2307 阅读 · 0 评论 -
POJ 1028 用栈模拟浏览器的前进与后退
poj 1028 Web NavigationTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 17718 Accepted: 7751DescriptionStandard web browsers contain features to move bac原创 2010-11-12 16:44:00 · 2935 阅读 · 0 评论 -
LeetCode Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty() --原创 2015-07-21 14:48:29 · 3307 阅读 · 0 评论