UVA501 - Black Box(vector + lower_bound)
来源:互联网 发布:怎样在淘宝网上交电费 编辑:程序博客网 时间:2024/05/12 08:07
UVA501 - Black Box(vector + lower_bound)
题目链接
题目大意:给你两种操作:Add num,将一个数加入黑盒子中,原本的黑盒子是空的。并且X = 0.Get
就是把X自增1,然后取出第X小的数。题目给的u序列的意思是在第Ui个数加入黑盒子后然后执行get操作。
解题思路:用vector来存放,这样能够实现随机取出第i小的数。然后用lower_bound函数来查找出比这个数大于等于的第一个数的位置,将这个数插入这个位置,复杂度n∗log(n),再用insert插入到vector的对应的位置。
代码:
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 3e4 + 5;vector<ll> v;vector<ll>::iterator it;int n, m;ll num[maxn];int op;int main () { int T; scanf ("%d", &T); while (T--) { scanf ("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf ("%lld", &num[i]); v.clear(); int dex = 0; for (int i = 0; i < m; i++) { scanf ("%d", &op); while (dex < op) { it = lower_bound(v.begin(), v.end(), num[dex]); if (it != v.end()) v.insert(it, num[dex++]); else v.push_back(num[dex++]); } printf ("%lld\n", v[i]); } if (T) printf ("\n"); } return 0;}
0 0
- UVA501 - Black Box(vector + lower_bound)
- UVa501
- UVA - 501 Black Box (优先队列或vector)
- Black Box
- Black Box
- Black Box
- Black Box
- zoj-1319-Black Box
- Black-box Test
- pku1442 Black Box
- poj 1442 Black Box
- POJ 1442 Black Box
- poj--1442--black box
- POJ 1442 Black Box
- POJ 1442 Black Box
- POJ 1442 Black Box
- uva 501 Black Box
- POJ 1442 Black Box
- Unable to execute dex: method ID not in [0, 0xffff]: 65536 的解决方案
- 100个常用的linux命令
- 首次部署struts时包的导入
- 随笔之我的未来不是梦
- Linuxx下密码暴力破解神器Hydra
- UVA501 - Black Box(vector + lower_bound)
- 移动团队交叉双迭代的敏捷实践
- SharePoint无代码工作流设计开发实例——交通费报销流程(一)
- 1046. Plane Spotting
- 手势识别
- lodop-web打印控件
- 结构模式之适配器模式(缺省适配器)
- hdu 5025——Saving Tang Monk
- SharePoint无代码工作流设计开发实例——交通费报销流程(二)