csu 1554: SG Value
来源:互联网 发布:java无参构造方法 编辑:程序博客网 时间:2024/05/21 14:43
1554: SG Value
Time Limit: 5 Sec Memory Limit: 256 MBSubmit: 336 Solved: 105
[Submit][Status][Web Board]
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
521 121 12
Sample Output
123
HINT
规律自己可以推
一开始,ans=1
插入x,当且仅当x<=1时,ans才会变,ans>1的话合成不了1
->ans=2
插入x,当且仅当x<=2时,ans才会变,ans>2的话合成不了2
->ans=ans+x
...
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cmath>#include<queue>#define Mod 1000000007#define ll long long#define N 1100#define INF 1010010010using namespace std;int n;int main() { //freopen("in.txt","r",stdin); while(~scanf("%d",&n)) { int op,x; ll ans=1; priority_queue<int,vector<int>,greater<int> >q; while(n--) { scanf("%d",&op); if(op==2) { printf("%lld\n",ans); continue; } scanf("%d",&x); if(x>ans) { q.push(x); continue; } q.push(x); while(q.size()&&ans>=q.top()) { ans+=q.top(); q.pop(); } } } return 0;}
0 0
- csu 1554: SG Value
- math --- CSU 1554: SG Value
- CSU 1554 SG Value —— 思维
- CSU 1554SG Value 动态维护最小不可组成的数
- SG Value
- sg
- SG
- sg
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- 程序员必须1小时内解决的5个编程问题
- android安全问题(三) 钓鱼程序
- 分别定义教师类和干部类 采用多重继承方式 第五章第九题
- stdarg.h编写可变参数函数
- Printf 的格式输出探索
- csu 1554: SG Value
- win7 拨号651
- W3C网页标准与优势
- 最向往的爱情
- 下载Android源代码错误汇总分析
- jquery插件开发样例-jquery插件开发(1)
- 在程序中使用继承和组合 第五章第十题
- Jquery 获取对象的几种方式介绍
- 接触ToolBar