本文整理汇总了C++中multiset::rbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ multiset::rbegin方法的具体用法?C++ multiset::rbegin怎么用?C++ multiset::rbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiset
的用法示例。
在下文中一共展示了multiset::rbegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
int n, m, a;
while ( scanf("%d", &n), n )
{
long long ans = 0LL;
urn.clear();
for (int i = 0; i < n; i++)
{
scanf("%d", &m);
for (int j = 0; j < m; j++)
{
scanf("%d", &a);
urn.insert( a );
}
ans += *urn.rbegin() - *urn.begin();
urn.erase( urn.begin() );
urn.erase( urn.find(*urn.rbegin()) );
}
printf("%lld\n", ans);
}
return 0;
}
示例2: main
int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
if (n==0) break;
LL ans = 0;
num.clear();
for (int i = 0; i < n; i++)
{
int k;
scanf("%d", &k);
for (int j = 0; j < k; j++)
{
int x;
scanf("%d", &x);
num.insert(x);
}
ans += *num.rbegin() - *num.begin();
num.erase(num.find(*num.begin()));
num.erase(num.find(*num.rbegin()));
}
printf("%I64d\n", ans);
}
return 0;
}
示例3: main
int main() {
int n, elm, k, t;
cin >> n >> t >> k;
for (int i = 0; i < n; ++i) {
cin >> elm;
v.push_back(elm);
}
for (int i = 0; i < k; ++i) {
S.insert(v[i]);
}
it = S.rbegin();
ans.push_back(*it);
for (int i = k; i < n; ++i) {
S.erase(S.find(v[i - k]));
S.insert(v[i]);
it = S.rbegin();
ans.push_back(*it);
}
int res = 0;
for (int i = 0; i < ans.size(); ++i) {
if (ans[i] <= t)
++res;
}
cout << res;
return 0;
}
示例4: findMedian
// Returns the median of current data stream
double findMedian() {
if (first.size()> second.size()) {
return *(first.rbegin());
}
double x = *first.rbegin();
double y = *second.begin();
return (x+y)/2;
}
示例5: median_ele
void median_ele()
{
//cout<<*s1.rbegin()<<endl;
//printf("%d\n",(*s1.rbegin()));
dint(*s1.rbegin());
s1.erase(s1.find(*s1.rbegin()));
if(s1.size()<s2.size())
{
s1.insert(*s2.begin());
s2.erase(s2.begin());
}
}
示例6: add_ele
void add_ele(int x)
{
if(s1.size()==s2.size())
{
s2.insert(x);
s1.insert(*s2.begin());
s2.erase(s2.begin());
}
else if(s1.size()>s2.size())
{
s1.insert(x);
s2.insert(*s1.rbegin());
s1.erase(s1.find(*s1.rbegin()));
}
}
示例7: main
int main() {
int n, q;
scanf("%d %d", &n, &q);
for (int i = 0; i < n; ++i) {
scanf("%d", a+i);
b[i] = a[i];
}
sort(a, a+n);
for (int i = 0; i < n; ++i) {
val.insert(a[i]);
if (i)
dif.insert(a[i] - a[i-1]);
}
while (q--) {
int t;
scanf("%d", &t);
if (t == 2) {
long long ans = *val.rbegin() - *val.begin();
ans -= *dif.begin();
printf("%lld\n", ans);
}
else {
int x, y;
scanf("%d %d", &x, &y);
--x;
if (b[x] != y) {
del(b[x]);
add(b[x] = y);
}
}
}
return 0;
}
示例8: main
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i].first);
}
for (int i = 0; i < n; i++) {
scanf("%d", &a[i].second);
tot += a[i].second;
}
sort(a, a + n);
int ans = ~0U >> 1;
for (int i = 0; i < n; i++) {
int j = i, sum = a[i].second;
while (j + 1 < n && a[j+1].first == a[i].first)
sum += a[++j].second;
int cnt = j - i + 1;
multiset<int>::reverse_iterator it = st.rbegin();
for (int k = 0; k < cnt - 1 && it != st.rend(); k++, it++) {
sum += *it;
}
ans = min(ans, tot - sum);
for (int k = i; k <= j; k++) {
st.insert(a[k].second);
}
i = j;
}
printf("%d\n", ans);
return 0;
}
示例9: if
vector<bool> Mochila(const multiset<Elemento> & elementos, double m) {
Nodo inic = NodoInicial(elementos, m);
double C = Greedy01(elementos,m);
priority_queue<Nodo> LNV;
LNV.push(inic);
double s = numeric_limits<double>::min();
vector<bool> resultado;
multiset<Elemento>::const_reverse_iterator raux = elementos.rbegin();
while (!LNV.empty()) {
Nodo x = (LNV.top());
LNV.pop();
if (x.CS >= C) {
for (unsigned k = 0; k < 2; k++) {
bool elec = (k==0) ? true : false;
Nodo y = Generar(x, elec, m,elementos);
if (y.nivel == elementos.size()-1 && y.valor_actual > s) {
s = y.valor_actual;
C = (C >= s) ? C : s;
resultado = y.tupla;
}
else if (y.nivel < elementos.size()-1 && y.CS >= C){
C = (C >= y.CI) ? C : y.CI;
LNV.push(y);
}
}
}
++raux;
}
return resultado;
}
示例10: main
int main(int argc, char *argv[]) {
std::ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
for(int i = 0; i < n; ++i)
cin >> a[i];
S.insert(a[0]);
int ma = 0, lo = 0, hi = 1;
while(true) {
if(*S.rbegin() - *S.begin() <= k) {
if(hi - lo > ma) {
ma = hi - lo;
ans.clear();
}
if(hi - lo == ma)
ans.push_back(lo);
if(hi == n)
break;
S.insert(a[hi++]);
} else {
S.erase(S.find(a[lo++]));
}
}
cout << ma << ' ' << ans.size() << endl;
for(int i = 0; i < (int)ans.size(); ++i)
cout << ans[i] + 1 << ' ' << ans[i] + ma << endl;
return 0;
}
示例11: main
int main(int argc, char const *argv[])
{
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%I64d", A + i);
s += A[i];
ps[i + 1] = ps[i] + A[i];
}
sum.insert(s);
qu.insert(Pii(n, 0));
for (int i = 0, p; i < n; ++i) {
scanf("%d", &p); --p;
auto it = qu.upper_bound(Pii(p, 0));
// cout << it->second << " " << it->first << endl;
ll tmp = ps[it->first] - ps[it->second];
// cout << "tmp " << tmp << endl;
sum.erase(sum.lower_bound(tmp));
tmp = ps[p] - ps[it->second];
// cout << "tmp " << tmp << endl;
sum.insert(tmp); qu.insert(Pii(p, it->second));
tmp = ps[it->first] - ps[p + 1];
// cout << "tmp " << tmp << endl;
sum.insert(tmp); qu.insert(Pii(it->first, p + 1));
qu.erase(it);
printf("%I64d\n", *sum.rbegin());
}
return 0;
}
示例12: encodeAllSymbols
void encodeAllSymbols(){
if (treeSet.empty()) {
return;
}
string pattern;
HuffmanNode* root = *(treeSet.rbegin());
_encodeAllSymbols(pattern, root);
}
示例13: pushup
void pushup() {
if (this == EMPTY) return ;
mxv = val;
if (s.size())
mxv = max(mxv, *s.rbegin());
if (ch[0] != EMPTY)
mxv = max(mxv, ch[0]->mxv);
if (ch[1] != EMPTY)
mxv = max(mxv, ch[1]->mxv);
}
示例14: balance
void balance() {
if (right.size() > left.size() + 1) {
left.insert(*right.begin());
right.erase(right.begin());
}
if (left.size() > right.size()) {
right.insert(*left.rbegin());
left.erase(--left.end());
}
}
示例15: rollback
ll rollback(){
//cout << "Rollbacking " _ pop << endl;
if(full.find(B[pop]) != full.end()){
full.erase(full.find(B[pop]));
ttime -= B[pop];
val -= A[pop];
}
else if(half.find(B[pop]) != half.end()){
half.erase(half.find(B[pop]));
val -= A[pop];
ttime -= (B[pop] + 1) / 2;
if(!full.empty()){
half.insert(*full.rbegin());
ttime -= (*full.rbegin() ) / 2;
auto it = full.end(); it--;
full.erase(it);
// full.erase(full.rbegin());
}
}
pop++;
}