题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 Description The SG value of a set (multiset) is the minimum positive integer that could not be constituted of the number in this set.You will be start with an empty set, now there are two o…
1554: SG Value Submit Page    Summary    Time Limit: 5 Sec     Memory Limit: 256 Mb     Submitted: 497     Solved: 167 Description The SG value of a set (multiset) is the minimum positive integer that could not be constituted of the number in this se…
https://leetcode.com/problems/find-median-from-data-stream/ 这道题目实在是不错,所以单独拎出来. https://discuss.leetcode.com/topic/27521/short-simple-java-c-python-o-log-n-o-1/2 看这里面的C++解法,用了priority_queue来实现的.(其实也是堆,之前我一直用multiset) 而Java用的PriorityQueue来做. 关于multiset…
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 这题在比赛的时候居然没想出来,然后发现居然是做过的题目的变种!!!! 先不考虑插入操作,就给定一堆数字,求出不能组成的最小的那个正数. 思路是,排序,然后维护一个区间[L, R]表示当前能组合成的数字.比如1.2就能组合成[1, 3]的所有数字. 那么下一个数a_i,我们需要其不能大于R + 1,否则会断,R + 1就是不能组合成的最小数字,比如a_i = 5就GG. 那么这题增加了插…
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 Description The SG value of a set (multiset) is the minimum positive integer that could not be constituted of the number in this set. You will be start with an empty set, now there are two…
SG Value Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1554 Mean: 一个可重集合,初始为空,每次插入一个值,询问这个集合的SG值(集合中的数字组合相加不能达到的最小值)是多少. analyse: 这题方法很巧妙. 假设当前不能达到的最小值为v,对于要插入的一个新值x 1)如果x>v,那么v的值不会改变,我们用一个优先队列(从小到大)将x进队; 2)如果x<=v,那么v的值会改变为v+x,然…
题目大意: 2种操作 1 a:往集合中添加一个元素a 2: 询问这个集合中的元素任意组合相加所不能得到的最小数的值 这道题总是不断地去找当前所能处的最小值能否被当前的最小值加上其前部的一堆可抵达数到达当前位置 也就是 minn < *s.begin() , 说明此时内部最小的元素是不影响这个值的,否则 minn+=*s.begin(),然后剔除最小值,不断往下访问 在这里因为相同数据也可以同时保存在集合内,所以不采用set(会删除重复元素),而是使用multiset. 在这里顺便学习理解一下mu…
1554: SG Value Time Limit: 5 Sec  Memory Limit: 256 MBSubmit: 140  Solved: 35 Description The SG value of a set (multiset) is the minimum positive integer that could not be constituted of the number in this set.You will be start with an empty set, no…
简介: 优先队列是一种容器适配器,优先队列的第一个元素总是最大或最小的(自定义的数据类型需要重载运算符).它是以堆为基础实现的一种数据结构. 成员函数(Member functions) (constructor): Construct priority queue (public member function)empty: Test whether container is empty (public member function)size: Return size (public mem…
优先队列(Priority Queue) A priority queue must at least support the following operations: insert_with_priority: add an element to the queue with an associated priority. pull_highest_priority_element: remove the element from the queue that has the highest…