CSU 1554 SG Value —— 思维
来源:互联网 发布:运动蓝牙耳机 知乎 编辑:程序博客网 时间:2024/06/04 22:47
题目链接: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
521 121 12
Sample Output
123
题解:
设当前的 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 —— 思维
- csu 1554: SG Value
- math --- CSU 1554: SG Value
- CSU 1554SG Value 动态维护最小不可组成的数
- SG Value
- Codeforces 484B Maximum Value——思维
- 博弈—SG
- CSU——1009
- CSU 1803 2016(思维)
- 博弈——sg函数和sg定理
- SG函数——简谈
- 博弈入门—NIM&SG
- CSU-1120——病毒
- CSU 1565 — Word Cloud
- CSU 1562 — Fun House
- CSU 1531 — Jewelry Exhibition
- CSU 1697 Surface Area of Cubes (思维)
- CSU 1803 2016 (逆向思维)
- 每天一个 Linux 命令(34):du 命令
- 关于SYS/BIOS
- 07、vue.js 之组件
- 不要62-三种写法
- Delphi中各个包中包含的控件
- CSU 1554 SG Value —— 思维
- 设计模式总论
- Linux中的Xargs
- Leetcode31. Next Permutation
- 内存中加载DLL DELPHI版
- MatrixManipulator类
- ZigBee_CC2530_01H_关于无线通信的结构体介绍
- ffpeg 简单视频压缩 普通需求类型
- 打印Java main参数