题目链接: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 opertions:

1. insert a number x into the set;

2. query the SG value of current set.

Input

Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1e5) -- the total number of opertions.

The next N lines contain one opertion each.

1 x means insert a namber x into the set;

2 means query the SG value of current set.

Output

For each query output the SG value of current set.

Sample Input

5
2
1 1
2
1 1
2

Sample Output

1
2
3

题解:

设当前的 SG value 为now,插入的值为x。

1.如果x>now, 那么now的值不会改变。把这个数放进集合中;

2.如果x<=now, 那么now += x, 由于此次now的增大,在集合中小于等于now的数,还能够使now继续增大。使得now增大之后,这个数应该从集合中删去。

(可以用优先队列或multiset维护这个集合)

学习之处:

升序的优先队列: priority_queue<LL, vector<LL>, greater<LL> >q;



代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-6;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+7;
const int maxn = 20; priority_queue<LL, vector<LL>, greater<LL> >q;//优先队列的升序写法
LL n, op, x, now; void init()
{
while(!q.empty()) q.pop();
now = 1;
} void solve()
{
while(n--)
{
scanf("%lld",&op);
if(op==1)
{
scanf("%lld",&x);
if(x>now)
{
q.push(x);
continue;
} now += x;
while(!q.empty() && now>=q.top())
{
now += q.top();
q.pop();
}
}
else printf("%lld\n", now);
}
} int main()
{
while(scanf("%lld",&n)!=EOF)
{
init();
solve();
}
return 0;
}

CSU 1554 SG Value —— 思维的更多相关文章

  1. csu 1554: SG Value 思维题

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 这题在比赛的时候居然没想出来,然后发现居然是做过的题目的变种!!!! 先不考虑插入操作, ...

  2. CSU 1554 SG Value (multiset/priority queue 思维题)

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554 Description The SG value of a set (mult ...

  3. math --- CSU 1554: SG Value

    SG Value Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1554 Mean: 一个可重集合,初始为空,每 ...

  4. CSU 1554 SG Value (集合类的学习)

    题目大意: 2种操作 1 a:往集合中添加一个元素a 2: 询问这个集合中的元素任意组合相加所不能得到的最小数的值 这道题总是不断地去找当前所能处的最小值能否被当前的最小值加上其前部的一堆可抵达数到达 ...

  5. 1554: SG Value (巧妙的模拟题,也属于思维题)

    1554: SG Value Submit Page    Summary    Time Limit: 5 Sec     Memory Limit: 256 Mb     Submitted: 4 ...

  6. CSUOJ 1554 SG Value

    1554: SG Value Time Limit: 5 Sec  Memory Limit: 256 MBSubmit: 140  Solved: 35 Description The SG val ...

  7. CSU 1547: Rectangle (思维题加一点01背包)

    1547: Rectangle Submit Page    Summary    Time Limit: 1 Sec     Memory Limit: 256 Mb     Submitted: ...

  8. 51nod 1554 KMP思维题

    题目为中文,因而不再解释题意. 首先遵循如下设定可以有以下几个结论:1,首先谈论下KMP的一个特殊性质:对于某一个特立独行的字符串:例如ABCDEF,在建立有限状态自动机之后,都会有,所有元素的失配边 ...

  9. csu 1551: Longest Increasing Subsequence Again BIT + 思维

    预处理last[i]表示以第i个开始,的合法后缀. pre[i]表示以第i个结尾,的合法前缀. 那么每一个数a[i],肯定是一个合法后缀last[i] + 一个合法前缀,那么合法前缀的数字要小于a[i ...

随机推荐

  1. codevs——1814 最长链

    1814 最长链  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 现给出一棵N个结点二叉树,问这棵二叉 ...

  2. n个平面把空间最多分成几个部分?

    题目: n个平面把空间最多分成几个部分? 解答: 1条直线可以把平面分成2部分,2条直线最多可以把平面分成4部分, 3条直线最多可以把平面分成几部分,4条直线呢?你能不能想出n条直线最多可以把平面分成 ...

  3. 【JVM】idea启动项目时候 添加jvm启动参数显示详细日志

    -verbose:class

  4. 【Navicat preminm】64位的Navicat preminm注册

    百度云盘 技术-->Navicat preminm+破解

  5. iOS -- SKViedoNode类

    SKViedoNode类 继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject(NSObject) ...

  6. scheme语言编写执行

    scheme是lisp的一种 编辑器能够用emacs.网上有非常多教导怎样编写的 (begin (display "hello") (newline)) 编写完以.scm保存,这里 ...

  7. Codeforces Round #277 (Div. 2)D(树形DP计数类)

    D. Valid Sets time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. HDMI

    HDMI,全称为(High Definition Multimedia Interface)高清多媒体接口,主要用于传输高清音视频信号. 现在是HDMI2.0.新一代的HDMI2.0较上一代最大的提升 ...

  9. VMware Workstation 11 安装MAC OS X 10.10 Yosemite(14B25)图解 2015-01-13 12:26:01|

    VMware Workstation 11 安装MAC OS X 10.10 Yosemite(14B25)图解 2015-01-13 12:26:01|  分类: 网络互联 |  标签:10.10  ...

  10. JSP学习笔记(一)

    JSP是基于JAVA语言的,区分大小写,HTML不区分大小写 如何建立Web服务目录? 1.在Webapps下面建立Web服务目录MYJSP 在Webapps下面新建文件夹MYJSP,将写好的jsp文 ...