关于如何使用 vector 水过 P7072 这档事
Trafford1894 · · 个人记录
先来了解
其中有两个参数,第一个是指针即你要插入的位置,第二个是你要插入的数。
那你肯定要问,位置怎么找?没有关系,用二分查找,algorithm 自带的函数。
假如说我们要在
vector<int>::iterator ind = lower_bound(vc.begin(), vc.end(), x);
vc.insert(ind, x);
由于
但是要注意:
时间复杂度:
上代码:
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
vector<int> arr;
vector<int>::iterator ps;
void Display(vector<int> vc) {
for (int i = 0; i < vc.size(); i++) cout << vc[i] << " ";
cout << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, w, curInt, ind;
cin >> n >> w;
for (int i = 1; i < n + 1; i++) {
cin >> curInt;
ps = lower_bound(arr.begin(), arr.end(), curInt);
arr.insert(ps, curInt);
//Display(arr);
ind = max(1, i * w / 100);
cout << arr[arr.size() - ind] << " ";
}
cout.flush();
return 0;
}