本文整理汇总了C++中multiset::size方法的典型用法代码示例。如果您正苦于以下问题:C++ multiset::size方法的具体用法?C++ multiset::size怎么用?C++ multiset::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiset
的用法示例。
在下文中一共展示了multiset::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetFormattedMedian
/* Function: GetFormattedMedian(const multiset<int>& minSet,
* const multiset<int>& maxSet)
* Usage: GetFormattedMedian(minSet, maxSet);
* -----------------------------------------------------------------------------
* Returns a string representation of the median value between the provided
* minset and maxset, consistent with the output specifications from the problem
* description.
*/
string GetFormattedMedian(const multiset<int>& minSet,
const multiset<int>& maxSet)
{
stringstream s;
if (minSet.size() > maxSet.size())
s << fixed << *FindMaxElement(minSet);
else if (minSet.size() < maxSet.size())
s << fixed << *FindMinElement(maxSet);
else
{
/* Cast the numerator as a long to prevent integer overflow when summing. */
long long sum = (long long)(*FindMaxElement(minSet))
+ *FindMinElement(maxSet);
/* Now we can ensure the median will hold the correct 32-bit value. */
double median = (double)(sum / 2.0);
if (median != (int)median)
s << setprecision(1);
else
s << setprecision(0);
/* Ensures that the median will be printed in decimal notation, as opposed
* to scientific notation.
*/
s << fixed << median;
}
return s.str();
}
示例2: dolnasrednia
void dolnasrednia(int srednia)
{
multiset<int> ocenycopy = oceny;
set<int>::iterator itbeg;
itbeg=ocenycopy.begin();
while(itbeg!=ocenycopy.end())
{
if((*itbeg)<=srednia)
{
pair <set<int>::iterator,set<int>::iterator> zasieg;
zasieg=ocenycopy.equal_range(*itbeg);
for(set<int>::iterator it=zasieg.first; *it< *zasieg.second;it++)
{
dolnasr.insert(*it);
ocenycopy.erase(it);
}
int sumael=0;
for(set<int>::iterator it=dolnasr.begin();it!=dolnasr.end();it++)
{
sumael+=(*it);
}
srednia=floor(sumael/dolnasr.size());
itbeg=ocenycopy.begin();
continue;
}
itbeg++;
}
int sumael=0;
for(set<int>::iterator it=dolnasr.begin();it!=dolnasr.end();it++)
{
sumael+=(*it);
}
skroc(sumael, dolnasr.size());
}
示例3: 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;
}
示例4: main
int main(){
ifstream fin("input.txt");
ofstream fout("output.txt");
int n, k;
long long tmp, t;
fin>>n>>k;
for(int i=0; i<n; ++i){
fin>>tmp;
if(q.size()==k){
t=*q.begin(); q.erase(q.begin());
q.insert(t+tmp);
} else q.insert(tmp);
}
while(q.size()>1) q.erase(q.begin());
fout<<*q.begin()<<endl;
fin.close();
fout.close();
return 0;
}
示例5: findMedian
double findMedian()
{
if (Large.size()>Small.size())
return *Large.begin();
else
return (*Large.begin()+*(--Small.end()))*1.0/2.0;
}
示例6: insert
void insert(int num)
{
if(median == -1) median = num;
else
{
if(num < median)
small_number_set.insert(num);
else
big_number_set.insert(num);
if(small_number_set.size() + 1 < big_number_set.size())
{
small_number_set.insert(median);
auto median_iter = big_number_set.begin();
median = *median_iter;
big_number_set.erase(median_iter);
}
else if(small_number_set.size() > big_number_set.size())
{
big_number_set.insert(median);
auto median_iter = prev(small_number_set.end());
median = *median_iter;
small_number_set.erase(median_iter);
}
}
}
示例7: 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;
}
示例8: 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());
}
}
示例9: 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());
}
}
示例10: if
void
pesquisa(int* vits, multiset<int> &sol, int feed)
{
//static int cou = 0;
//fout << cou++ << endl;
//imprime_sol(sol);
/*fout << endl;
for (int i = 0; i < nVit; i++) {
fout << vits[i] << " ";
}
fout << endl << endl;*/
if (acabado(vits)) {
if (sol.size() < solucao.size() || solucao.size() == 0) {
solucao = sol;
}
else if (sol.size() == solucao.size()) {
multiset<int>::iterator it = sol.begin(), it2 = solucao.begin();
for ( ; it != sol.end(); it++, it2++) {
if (*it < *it2) {
solucao = sol;
break;
}
}
}
return;
}
else if (feed > nFeeds) {
return;
}
int temp[MAXV];
memcpy(temp, vits, sizeof(int)*nVit);
aplicaFeed(temp, vits, feed);
if (melhor_(temp, vits)) {
multiset<int> nova_sol = sol;
nova_sol.insert(feed);
pesquisa(temp, nova_sol, feed+1);
}
memcpy(temp, vits, sizeof(int)*nVit);
multiset<int> nova_sol = sol;
pesquisa(temp, nova_sol, feed+1);
}
示例11: check
bool check()
{
if(tcnt < st.size()) return 0 ;
scnt=0 ;
for(int i=0;!st.empty() && i<tcnt;i++)
{
auto it=st.upper_bound(tmp[i]) ;
if(it!=st.begin())
it-- , st_tmp[scnt++]=*it , st.erase(it) ;
}
int sz=st.size() ;
for(int i=0;i<scnt;i++) st.insert(st_tmp[i]) ;
return sz==0 ;
}
示例12: Adjust
void Adjust(int* mid)//调整中位数
{
if(upper.size()>lower.size())
{
lower.insert(*upper.begin());
upper.erase(upper.begin());
}
else if(lower.size()>upper.size()+1)
{
upper.insert(*lower.begin());
lower.erase(lower.begin());
}
(*mid)=*lower.begin();
}
示例13: 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()));
}
}
示例14: adjust
void adjust(){
long long val;
if(!minset.empty()){
if(!maxset.empty()){
if(maxset.size() > minset.size()){
it = maxset.begin();
val = *it;
maxset.erase(it);
minset.insert(val);
adjust();
}
else if(minset.size() - maxset.size() > 1){
it = minset.end();
it--;
val = *it;
minset.erase(it);
maxset.insert(val);
adjust();
}
}
else{
if(minset.size() > 1){
it = minset.end();
it--;
val = *it;
minset.erase(it);
maxset.insert(val);
adjust();
}
}
}
else{
if(!maxset.empty()){
it = maxset.begin();
val = *it;
maxset.erase(it);
minset.insert(val);
adjust();
}
}
}
示例15: main
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while(t--){
S.clear();
cin >> n;
for(int i=0;i<n;i++){
cin >> x;
it = S.upper_bound(x);
if(it==S.end()){
S.insert(x);
}
else{
S.erase(it);
S.insert(x);
//(*it) = x;
}
}
cout << S.size() << " ";
for(multiset<int>::iterator it=S.begin();it!=S.end();it++){
cout << (*it) << " ";
}
cout << endl;
}
return 0;
}