HDU4006
来源:互联网 发布:才真旺姆解释双修 知乎 编辑:程序博客网 时间:2024/06/04 18:54
题目要求:
给你一个数列,两种命令,第一种:加入一个值,第二个命令:求出第k大的值。
反思:
这道题一直RunTime Error,最后才发现当要加入的位置是最后一位时,则待插入的位置,已经出了 vector 的界限了,故要加入判定。
以后遇问题多从不同的角度去思考,不断思考,不然就换题。
#include <iostream>#include <cstdio>#include <cmath>#include<vector>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;const int inf=0x3f3f3f3f;int coun=0;int main(){ int n,k; while(cin>>n>>k) { vector<long long>vec(1000100); vec.resize(0); for(int i=0; i<n; ++i) { long long val; char m; cin>>m; if(m=='I') { scanf("%lld",&val); int l=0,r=coun-1; coun++; while(l<=r) { int mid=(l+r)>>1; if(vec[mid]<val) { r=mid-1; } else { l=mid+1; } } if(l<0) l=0; if(l<=vec.size()-1) vec.insert(vec.begin()+l,val); else vec.push_back(val); } if(m=='Q') { printf("%lld\n",vec[k-1]); } } } return 0;}
0 0
- hdu4006
- hdu4006
- HDU4006
- HDU4006
- hdu4006
- hdu4006优先队列
- hdu4006(优先队列)
- HDU4006-优先队列
- HDU4006(优先队列)
- HDU4006 The kth great number
- HDU4006--The kth great number
- HDU4006(The kth great number)
- 优先队列(priority)--hdu4006
- 【HDU4006】The kth great number
- hdu4006: The kth great number
- HDU4006 The kth great number
- hdu4006 The kth great number
- HDU4006-The kth great number(优先队列)
- 2015级C++第16周程序阅读 文件操作
- 文章标题
- 爸第一次来大学
- Python学习笔记 —— 字典
- 函数popen()
- HDU4006
- DrawerLayout的入门
- 服务器nginx+nodejs配置
- iOS应用发布篇一(开发者账号申请)
- 一个32岁入门的70后程序员给我的启示
- matlab 可视化 —— axis
- Python 各种测试框架简介(一):doctest
- Jenkins distributed builds - master/slave
- foreach的原理