csu 1554: SG Value 思维题
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。
那么这题增加了插入操作。
我们只需要维护其递增排序,查询的时候,按照上面思路查询就好了。
比如1、2、5,那么前两个数可以组合成[1, 3],就可以把那两个数字pop掉了,不用重复计算。
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <assert.h> #define IOS ios::sync_with_stdio(false) using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL;#include <iostream> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <string> #include <bitset> multiset<LL>ss; int n; void work() {LL R = 0;ss.clear();for (int i = 1; i <= n; ++i) {int op;cin >> op;if (op == 2) {while (ss.size() && *ss.begin() <= R + 1) {R = R + *ss.begin();ss.erase(ss.begin());}cout << R + 1 << endl;} else {LL val;cin >> val;ss.insert(val);}} }int main() { #ifdef localfreopen("data.txt", "r", stdin); // freopen("data.txt", "w", stdout); #endifwhile (cin >> n) work();return 0; }
View Code
转载于:https://www.cnblogs.com/liuweimingcprogram/p/6738258.html
csu 1554: SG Value 思维题相关推荐
- little w and Soda(思维题)
链接:https://ac.nowcoder.com/acm/contest/297/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- yoyo思维题(困难) 组合数学
问题 B: yoyo思维题(困难) 时间限制: 1 Sec 内存限制: 256 MB 提交: 11 解决: 3 [提交][状态][讨论版][命题人:qianyouyou][Edit] [TestD ...
- 1884: 三个家庭(思维题)
1884: 三个家庭 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 244 Solved: 81 [Submit][Status][Web Board] ...
- 思维题 UVA 10881 Piotr's Ants
题目传送门 1 /* 2 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 3 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 4 关键2:蚂蚁的相对位置 ...
- CF--思维练习-- CodeForces - 215C - Crosses(思维题)
ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered fr ...
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
- CodeForces - 1102A(思维题)
https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...
- ☆【CodeForces - 764C】Timofey and a tree (思维题,树的性质)
题干: Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After tha ...
最新文章
- php 企业微信指令回调借款_企业微信外部联系人回调事件
- python引用大数据,Python 3 UDF
- 你让,勋爵? 使用Jenkins声明性管道的Docker中的Docker
- 李宏毅机器学习笔记day1
- unity2021游戏引擎安装激活并汉化
- 使用RMAN备份与恢复数据库(2)——参数文件的备份与恢复
- Ubuntu-图形界面和字符界面切换快捷键
- 已知直线方程,计算直线对应的向量
- python下载m3u8文件视频
- 提升思维品质,不可不知的5个工具
- Spring MVC之redirect、forward和普通跳转
- 分水岭算法--语义分割
- win系统如何运行msi后缀文件
- cesium 鼠标点击pick与drillPick的区别
- Server 2016/Windows 10使用域管理员账户操作提示权限不足的问题
- 【SHOI 2002】百事世界杯之旅
- Unity简单使用Job System
- 古典密码学、DES对称加密、3DES对称加密知识总结和实验
- 项目管理(项目经理)与规划
- 中国软件开发者薪资调查报告
热门文章
- Hadoop 2.7.3 完全分布式维护-动态增加datanode篇
- javaMail发邮件
- Goldengate 应用环境 mysql to oracle
- asp.net中DropDownList的SelectedIndexChanged触发问题
- 如何用python制作九九乘法表_“九九乘法表”案例理解python循环语句
- 普通平键的主要尺寸有_餐厅放多大尺寸的餐桌合适?这几种尺寸,适合所有户型...
- python批量读取grib_windows python读取grib2数据
- php 文件迭代对象,通过PHP中的stdClass对象进行迭代
- GDB调试器使用手册
- Java设计模式之十一 ---- 策略模式和模板方法模式