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 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
题目意思:
两种操作
1 a :往集合添加一个元素a
2:询问这个集合中任意元素相加不能得到的最小数的值
这道题总是不断地去找当前所能处的最小值能否被当前的最小值加上其前部的一堆可抵达数到达当前位置
也就是 minn < *s.begin() , 说明此时内部最小的元素是不影响这个值的,否则 minn+=*s.begin(),然后剔除最小值,不断往下访问
在这里因为相同数据也可以同时保存在集合内,所以不采用set(会删除重复元素),而是使用multiset。
 
 
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define max_v 10005
using namespace std;
typedef long long LL;
multiset<int> s;
int main()
{
int n;
while(cin>>n)
{
s.clear();
LL minv=;
for(int i=;i<n;i++)
{
int op;
cin>>op;
if(op==)
{
int v;
cin>>v;
s.insert(v);
}else
{
while(!s.empty()&&minv>=*s.begin())
{
minv+=*s.begin();
s.erase(s.begin());
}
printf("%lld\n",minv);
}
}
}
return ;
}
/* 题目意思:
两种操作
1 a :往集合添加一个元素a
2:询问这个集合中任意元素相加不能得到的最小数的值 这道题总是不断地去找当前所能处的最小值能否被当前的最小值加上其前部的一堆可抵达数到达当前位置
也就是 minn < *s.begin() , 说明此时内部最小的元素是不影响这个值的,否则 minn+=*s.begin(),然后剔除最小值,不断往下访问
在这里因为相同数据也可以同时保存在集合内,所以不采用set(会删除重复元素),而是使用multiset。 /*

1554: SG Value (巧妙的模拟题,也属于思维题)的更多相关文章

  1. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)(A.思维题,B.思维题)

    A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  2. 【巧妙的模拟】【UVA 10881】 - Piotr's Ants/Piotr的蚂蚁

    </pre></center><center style="font-family: Simsun;font-size:14px;"><s ...

  3. 【每日一题】 UVA - 213 Message Decoding 模拟解码+读入函数+阅读题

    题意:阅读理解难度一道比一道难orz.手摸了好久样例 题解: 读入:大循环用getline读入header顺便处理一下,  里面再写两重循环,外层一次读三个串,内层一次读num个串. 之后就查表,线性 ...

  4. CSUOJ 1554 SG Value

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

  5. 【2019.7.15 NOIP模拟赛 T1】夹缝(mirror)(思维题)

    思维题 此题应该是比较偏思维的. 假设一次反射后前进的距离是\(2^x(2y+1)\),则显然,它可以看做是前进距离为\(2^x\)的光线经过了\((2y+1)\)次反射,两者是等价的,甚至后者可能还 ...

  6. 实验仓 #779.【CSP2019模拟 Day 1】A题

    题目传送门 考场上面做了一个暴力的做法,然后,然后他$WA$了. emmm...($T$就算了吧,$WA$了算什么事啊) 好吧,这道题,其实好像...是一道思维题来着. 如果出现了这样两个打X的格子上 ...

  7. 【字符串大模拟】潜伏者—— NOIP2009原题

    洛谷连接 就一道黄题没啥可以说的……就是要细心…… 学到了神奇的优化 ios::sync_with_stdio(false); cin优化,能跑的比scanf快!棒!(不过要开std) 这题真的还挺简 ...

  8. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  9. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

随机推荐

  1. [转]c# winform tcp connect timeout 连接超时设置

    转自:https://www.cnblogs.com/jhlong/p/5622336.html 简单的c# TCP通讯(TcpListener) C# 的TCP Socket (同步方式) C# 的 ...

  2. Angular面试题四

    二十.angular 的缺点有哪些? 1.强约束 导致学习成本较高,对前端不友好. 但遵守 AngularJS 的约定时,生产力会很高,对 Java 程序员友好. 2.不利于 SEO 因为所有内容都是 ...

  3. onscroll事件没有响应的原因以及vue.js中添加onscroll事件监听的方法

    1 onscroll事件失效 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  4. 深度研究Oracle数据库临时数据的处理方法

    在Oracle数据库中进行排序.分组汇总.索引等到作时,会产生很多的临时数据.如有一张员工信息表,数据库中是安装记录建立的时间来保存的.如果用户查询时,使用Order BY排序语句指定按员工编号来排序 ...

  5. YOLO object detection with OpenCV

    Click here to download the source code to this post. In this tutorial, you’ll learn how to use the Y ...

  6. python学习笔记之——python模块

    1.python模块 Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句. 模块让你能够有逻辑地组织你的 Python ...

  7. linux 目录操作命令 mkdir、rmdir、cd -、cp、scp、mv、rm

    mkdir /bin/mkdir-p [目录名] 递归创建 mkdir /tmp/testmkdir /tmp/noexit/test在一个不存在的目录下创建一个目录test,要使用-p选项 可以创建 ...

  8. [转载]python——事件驱动的简明讲解

    本文转载自http://www.cnblogs.com/thinkroom/p/6729480.html 作者:码匠信龙 方便自己今后查阅存档 关键词:编程范式,事件驱动,回调函数,观察者模式 --- ...

  9. WinForm自定义控件

        [ToolboxBitmap(typeof(PropertyGrid))]//设置在工具箱中显示的小图标 public partial class ServiceManage : UserCo ...

  10. 转:C# 线程同步技术 Monitor 和Lock

    原文地址:http://www.cnblogs.com/lxblog/archive/2013/03/07/2947182.html 今天我们总结一下 C#线程同步 中的 Monitor 类 和 Lo ...