本文整理汇总了C++中multiset::rend方法的典型用法代码示例。如果您正苦于以下问题:C++ multiset::rend方法的具体用法?C++ multiset::rend怎么用?C++ multiset::rend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiset
的用法示例。
在下文中一共展示了multiset::rend方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: Greedy01
double Greedy01(const multiset<Elemento> & objetos, const double pesoM){
double pesoact = 0, beneficio = 0;
multiset<Elemento>::const_reverse_iterator it;
for(it = objetos.rbegin(); it != objetos.rend() && pesoact < pesoM; ++it)
if((pesoact + (*it).peso) <= pesoM){
beneficio += (*it).beneficio;
pesoact += (*it).peso;
}
return beneficio;
}
示例3: GreedyFraccional
double GreedyFraccional(const double lim_peso, const multiset<Elemento> & objetos){
double pesoact = 0, beneficio = 0;
multiset<Elemento>::const_reverse_iterator it;
for(it = objetos.rbegin(); it != objetos.rend() && pesoact < lim_peso; ++it){
if((pesoact + (*it).peso) <= lim_peso){
beneficio += (*it).beneficio;
pesoact += (*it).peso;
}
else {
double fraccion = (lim_peso-pesoact)/(*it).peso;
beneficio += fraccion * (*it).beneficio;
pesoact = lim_peso;
}
}
return beneficio;
}
示例4: main
int main()
{
freopen("C:\\Users\\crazyacking\\Desktop\\cin.txt","r",stdin);
// freopen("C:\\Users\\crazyacking\\Desktop\\cout.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
int cas;
cin>>cas;
while(cas--)
{
cin>>L>>N>>K;
int x,m;
int cnt=1;
for(int i=0;i<N;++i)
{
cin>>x>>m;
while(x!=0 && m--)
{
apple.insert(make_pair(x,cnt++));
}
}
debug();
LL ans=0;
LL mid=L/2;
int container;
multiset<pair<int,int> >::iterator ibe,it,tmp;
for(ibe=apple.begin();ibe!=apple.end() && (*ibe).first<mid;)
{
container=0;
while(container!=K && (*ibe).first<mid)
{
ibe++;
container++;
}
--ibe;
if(container==K)
{
it=ibe;
ans+=(*it).first*2;
for(int i=0;i<K;++i)
{
it=apple.begin();
apple.erase(*it);
}
}
else break;
}
debug();
multiset<pair<int,int> > :: reverse_iterator rev=apple.rbegin(),rit;
for(rev=apple.rbegin();rev!=apple.rend() && (*rev).first>=mid;)
{
container=0;
while(container!=K && (*rev).first>=mid)
{
rev++;
container++;
}
rev--;
if(container==K)
{
rit=rev;
cout<<"hehe="<<(*rit).first<<endl;
ans+=(L-(*rit).first)*2;
for(int i=0;i<K;++i)
{
rit=apple.rbegin();
apple.erase(*rit);
}
}
else break;
}
if(apple.size()<K)
{
ans+=L; // run a cycle
}
else // 3 case
{
int r=-1-0x7fffffff,l=0x7fffffff;
multiset<pair<int,int> > :: iterator it;
for(it=apple.begin();it!=apple.end();++it)
{
if((*it).first<mid) r=max(r,(*it).first);
else l=min(l,(*it).first);
}
LL dis1=0,dis2=0,dis3=0;
if(r!=-1-0x7fffffff)
{
dis1+=r;
}
if(l!=0x7fffffff)
{
dis1+=L-l;
}
for(container=0,it=apple.begin();it!=apple.end()&&container !=K;++it,++container){}
dis2+=L+(L-(*it).first)*2;
for(container=0,it=apple.end();it!=apple.begin()&&container!=K;--it,container++){}
dis3+=L+(*it).first*2;
LL dis=min(dis1,min(dis2,dis3));
//.........这里部分代码省略.........