二分uva501
来源:互联网 发布:网络电视怎么放音乐 编辑:程序博客网 时间:2024/05/20 03:44
思路:vector保存元素,每次插入的时候二分位置,然后插入,询问的时候直接用下标操作
#include<iostream>#include<set>#include<vector>#include<cstdio>using namespace std;const int maxn=30010;int n,m;int add[maxn];void solve(){ vector<int> a; int x,j=1; for(int i=0; i<m; i++) { cin>>x; while(a.size()!=x) { vector<int>::iterator it=lower_bound(a.begin(),a.end(),add[j]); a.insert(it,add[j++]); } cout<<a[i]<<endl; }}int main(){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif int t; cin>>t; bool first=true; while(t--) { if(first)first=false; else cout<<endl; cin>>n>>m; for(int i=1; i<=n; i++)cin>>add[i]; solve(); } return 0;}
0 0
- 二分uva501
- UVa501
- UVA501 - Black Box(vector + lower_bound)
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分。
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分~~
- 算法导论(第三版)15.1-5(斐波那契数列问题)
- 传统百货扎堆试水O2O
- 黑马程序员01_多线程
- Gas Station
- HDU 4135容斥原理求互质的个数
- 二分uva501
- STL:排序
- PHP编码规范(2)
- 深入浅出MFC系列 第11章和12章的学习笔记
- VC基本操作四十条
- GTD 实战与总结
- UVA1513--Movie collection--线段树
- 假币的型号
- HDU 4745 Two Rabbits (最长回文变形)