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. window平台安装node.js绿色版

    1. 下载Windows Binary版本的node.js文件 2. 把下载的ZIP压缩包解压到某个目录下(例如:D:\nodejs) 3. 此时的node.js只在刚刚解压的目录才起作用,需要配置环 ...

  2. Django基础二之URL路由系统

    一 URL配置 Django 1.11版本 URLConf官方文档 URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表.你就是以这 ...

  3. vscode 代码跳转之PHP篇

    1.安装插件:PHP IntelliSense 2.配置:"php.executablePath": "C:\\php\\php.exe", 但是目前有问题,跨 ...

  4. ubuntu下创建虚拟python3开发环境

    友情链接:ubuntu16.04下安装python3+创建虚拟python3开发环境 1.为什么要创建python3虚拟开发环境? /********************************* ...

  5. OAuth2学习笔记

    参考:https://aaronparecki.com/oauth-2-simplified/ 1.角色定义 应用程序(客户) 需要获取用户的账号信息,获得相关权限. API服务器 资源服务器就是AP ...

  6. 使用MaxCompute访问TableStore(OTS) 简明手册

    摘要: 大数据计算服务 MaxCompute 能够提供强大的分析能力,而分布式 NoSQL 数据库表格存储在行级别上的实时更新和可覆盖性写入等特性,相对于 MaxCompute 内置表 append- ...

  7. mkdir failed for img Read-only file system

    最简单的方法就是打开模拟起,然后 windows-->show view-->file explorer-->mnt-->sdcard (最好在该目录下重新创建个文件夹)选中文 ...

  8. maven 编译插件指定jdk版本的两种方式

    第一种方式: <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration&g ...

  9. 深入理解SVG坐标体系和transformations- viewport, viewBox,preserveAspectRatio

    本文翻译自blog: https://www.sarasoueidan.com/blog/svg-coordinate-systems/ SVG元素不像其他HTML元素一样受css盒子模型所制约.这个 ...

  10. IPv4到IPv6的三种过渡技术

    1. 双协议栈 ( Dual Stack, RFC2893 ) 主机同时运行IPv4和IPv6两套协议栈,同时支持两套协议. 2. 隧道技术 ( Tunnel, RFC2893 ) 这种机制用来在IP ...