本文整理汇总了C++中map::rbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ map::rbegin方法的具体用法?C++ map::rbegin怎么用?C++ map::rbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map
的用法示例。
在下文中一共展示了map::rbegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrintStat
void PrintStat(long long genome_size) {
// total length
int64_t total_length = 0;
int64_t total_contigs = 0;
int64_t average_length = 0;
for (auto it = histogram.begin(); it != histogram.end(); ++it) {
total_length += it->first * it->second;
total_contigs += it->second;
}
if (genome_size == 0) { genome_size = total_length; }
if (total_contigs > 0) {
average_length = total_length / total_contigs;
}
// N50
int64_t n50 = -1;
int64_t acc_length = 0;
for (auto it = histogram.rbegin(); it != histogram.rend(); ++it) {
acc_length += it->first * it->second;
if (n50 == -1 && acc_length * 2 >= genome_size) {
n50 = it->first;
break;
}
}
printf("Total length: %ld, N50: %ld, Mean: %ld, number of contigs: %ld\n", total_length, n50, average_length, total_contigs);
printf("Maximum length: %ld\n", histogram.size() > 0 ? histogram.rbegin()->first : 0);
}
示例2: GradedReverse
bool GradedReverse(map <VarNames, int> const &A,
map <VarNames, int> const &B) {
// Total Degree comparison
int TotalDegree1 = 0;
int TotalDegree2 = 0;
for ( auto var : A ) TotalDegree1 += var.second;
for ( auto var : B ) TotalDegree2 += var.second;
if ( TotalDegree1 != TotalDegree2 ) return TotalDegree1 < TotalDegree2;
// Inverted lex
auto it1 = A.rbegin();
auto end1 = A.rend();
auto it2 = B.rbegin();
auto end2 = B.rend();
while ( it1 != end1 and it2 != end2 and (*it1) == (*it2) ) {
it1++;
it2++;
}
if ( it1 == end1 and it2 == end2 ) return false; //equality
else if ( (*it1).first != (*it2).first ) {
return (*it1).first > (*it2).first;
}
else {
return (*it1).second > (*it2).second;
}
}
示例3:
map<mmyyyy, UI> barchart_hits_map(const map<mmddyyyy, UI> &k)
{
map<mmyyyy, UI> hits;
{
// built hits maps with zeroes
mmyyyy first, last;
first.mm = k.begin()->first.mm;
first.yyyy = k.begin()->first.yyyy;
last.mm = k.rbegin()->first.mm;
last.yyyy = k.rbegin()->first.yyyy;
while(!(last<first)) // last>=first
hits[first++] = 0;
}
// fill up hits with numbers
mmyyyy t;
for(map<mmddyyyy, UI>::const_iterator i=k.begin(); i!=k.end(); i++)
{
t.mm = i->first.mm;
t.yyyy = i->first.yyyy;
if(hits.find(t)!=hits.end())
hits[t] += i->second;
}
return hits;
}
示例4: initiateCellMove
void initiateCellMove()
{
int initialCutset = calculateCutsetSize();
int cutSet = 0;
int counter=0;
cout<<"initial Cutset = "<<initialCutset<<endl;
int cellId =0;
int temp =0;
map<int,list<int> >::reverse_iterator it1 = gainToCellIdListMap.rbegin();
while( it1 != gainToCellIdListMap.rend())
{
cout<<"for cell of gain "<<it1->first<<endl;
bool setbreak = false;
list<int>::iterator it2 = (it1->second).begin();
while( it2!= (it1->second).end())
{
if(cellIdToCellMap[*it2].getIsLocked()== false)
{
cout<<"toggling bit of cell "<<cellIdToCellMap[*it2].cellID<<" "<<cellIdToCellMap[*it2].partition<<endl;
cellIdToCellMap[*it2].changePartition();
cout<<"new partition "<<cellIdToCellMap[*it2].partition<<endl;
if(checkAreaConstraint() == false)
{
cellIdToCellMap[*it2].changePartition();
cout<<"reverting partition -> area constraint not met" <<endl;
++it2;
continue;
}
else
{
cellIdToCellMap[*it2].setIsLocked();
cout<<"Cell "<<*it2 <<" isLocked" << cellIdToCellMap[*it2].getIsLocked()<<endl;
counter++;
cutSet = calculateCutsetSize();
cout<<"cutset size after "<< counter <<" move = "<<cutSet<<endl;
setbreak = true;
break;
}
}
// cout<<"isLocked "<<cellIdToCellMap[*it2].getIsLocked()<<endl;
}
if(setbreak==true)
{
makeGainBucket();
it1=gainToCellIdListMap.rbegin();
//it2 = (it1->second).begin();
continue;
}
it1++;
}
}
示例5: updateGainBucket
void updateGainBucket(int cellId)
{
int gain =0;
for(list<int> ::iterator it1 = cellIdToCellMap[cellId].netList.begin(); it1!=cellIdToCellMap[cellId].netList.end();++it1)
{
for(list<int>::iterator it2 = netToCellListMap[*it1].begin(); it2!= netToCellListMap[*it1].end();++it2)
{
for(map<int,list<int> >::reverse_iterator it3 = gainToCellIdListMap.rbegin(); it3 != gainToCellIdListMap.rend(); ++it3)
{
list<int>::iterator it4 = (it3->second).begin();
while(it4 != (it3->second).end())
{
if(*it4 == *it2)
{
it4 = (it3->second).erase(it4);
cout<<"removing cell from gain list "<< *it2<<endl;
continue;
}
++it4;
}
}
gain = calculateGain(*it2);
map<int, std::list<int> >::iterator finder;
finder = gainToCellIdListMap.find(gain);
if(finder==gainToCellIdListMap.end())
{
list<int> celllist;
celllist.push_back(*it2);
gainToCellIdListMap.insert(pair<int,list<int> >(gain,celllist));
}
else
finder->second.push_back(*it2);
}
}
cout<<"updated gain bucket is"<<endl;
cout<<"gain Cell list"<<endl;
for(map<int,list<int> >::const_reverse_iterator it1 = gainToCellIdListMap.rbegin(); it1 != gainToCellIdListMap.rend(); ++it1)
{
cout<<it1->first<<" ";
for(list<int>::const_iterator it2 = (it1->second).begin(); it2!= (it1->second).end(); ++it2)
{
cout<<*it2<<" ";
}
cout<<endl;
}
}
示例6: make_pair
pair<int,int> calc(const map<int,int> &M)
{
if (M.empty()) {
return make_pair(0, 1);
}
if (M.rbegin()->second + 1 <= B) {
return make_pair(M.rbegin()->first, M.rbegin()->second + 1);
} else {
return make_pair(M.rbegin()->first + 1, 1);
}
}
示例7: main
int main() {
int n;
cin>>n;
for (int i = 0; i < n; ++i)
{
int x;
// cin>>x;
scanf("%d",&x);
l.push_back(x);
DP[x]++;
}
for (int i = 0; i < n; ++i)
{
int x;
// cin>>x;
scanf("%d",&x);
T[x][l[i]]++;
}
int ans=1e9;
std::map<int,int>::reverse_iterator rit;
int sum=0;
int nremoved=0;
for (rit = DP.rbegin(); rit !=DP.rend() ; ++rit)
{
int l=rit->first;
int k=rit->second;
int rem=max(0,n-nremoved-2*k+1);
int val=0;
// cout<<"rem "<<rem<<endl;
for (int i = 1; i <=200 && rem>0 ; ++i)
{
for (map<int,int>::iterator it = T[i].begin(); it !=T[i].end() && rem>0; ++it)
{
if(it->first==l)
continue;
else{
int p=min(it->second,rem);
val+=i*p;
rem-=p;
}
}
}
ans=min(ans,sum+val);
for (int i = 1; i <= 200; ++i)
{
// while(T[i].find(l)!=T[i].end()){
// sum+=i;
// nremoved++;
// T[i].erase(T[i].find(l));
// }
nremoved+=T[i][l];
sum+=i*T[i][l];
T[i].erase(T[i].find(l));
}
// cout<<"sum "<<sum<<endl;
}
// cout<<ans<<endl;
printf("%d\n",ans );
return 0;
}
示例8: main
int main(int argc, char** argv) {
// freopen("in", "r", stdin);
scanf("%d%d%d", &n, &m, &k);
for(int i = 0; i < n; ++i){
int x; scanf("%d", &x);
a[x]++;
}
for(int i = 0; i < m; ++i){
int x; scanf("%d", &x);
a[x]--;
}
int alice = 0, bob = 0;
for(map<int, int>::reverse_iterator it = a.rbegin(); it != a.rend(); ++it){
int fish = (*it).second;
if(fish == 0) continue;
if(fish > 0){
alice += fish;
}else{
bob -= fish;
}
if(alice > bob){
puts("YES");
return 0;
}
}
puts("NO");
return 0;
}
示例9: main
int main(void) {
int N, K, score, k, l, num(0);
string id;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> K;
num += K;
for (int j = 0; j < K; j++) {
cin >> id >> score;
local[i][score].insert(id);
total[score].insert({id, 0});
location[id] = i+1;
}
int l = k = 1;
for (auto elem = local[i].rbegin(); elem != local[i].rend(); ++elem) {
for (auto& it : (*elem).second) {
total[(*elem).first][it] = l;
k++;
}
l = k;
}
}
cout << num << endl;
l = k = 1;
for (auto elem = total.rbegin(); elem != total.rend(); ++ elem) {
for (auto& it : (*elem).second) {
cout << it.first << " " << l << " " << location[it.first] << " " << it.second << endl;
k++;
}
l = k;
}
return 0;
}
示例10: TriggerExplosion
void TriggerExplosion ( Texture* tex, GLfloat x, GLfloat y, GLfloat Blastradius ) {
cout<<"TriggerExplosion: ExplosionsList.size()="<<ExplosionsList.size() <<endl;
bStartshaking = true;
//exit(50);
// int i;
cout<<"------------->explosion() called"<<endl;
//add new element to the map
if ( ExplosionsList.empty() ) ExplosionsList[0]=explosion();
else ExplosionsList[ ( ExplosionsList.rbegin() )->first+1]=explosion();
cout<<"------------->explosion() call finished"<<endl;
//exit(0);
ExplosionsList[ExplosionsList.size()-1].iterateSheets = true;
ExplosionsList[ExplosionsList.size()-1].animationTimer.Start();
ExplosionsList[ExplosionsList.size()-1].Load ( tex, 4, 4 );
ExplosionsList[ExplosionsList.size()-1].Scale ( Blastradius/30.0 );
// for ( i=0; i < ExplosionsList.size(); i++ ) {
ExplosionsList[ExplosionsList.size()-1].x = x;
ExplosionsList[ExplosionsList.size()-1].y = y;
ExplosionsList[ExplosionsList.size()-1].Active = true;
ExplosionsList[ExplosionsList.size()-1].CurrentFrame = 0;
ExplosionsList[ExplosionsList.size()-1].startTicks = Timer[0].GetTicks();
cout<<"setting speed"<<endl;
ExplosionsList[ExplosionsList.size()-1].setAnimationSpeed ( 16.0f );
// }
cout<<"explosion at ("<<ExplosionsList[ExplosionsList.size()-1].x<<","<<ExplosionsList[ExplosionsList.size()-1].y<<")"<<endl;
}
示例11: derive
result_t ValueListDataField::derive(string name, string comment,
string unit, const PartType partType,
int divisor, map<unsigned int, string> values,
vector<SingleDataField*>& fields)
{
if (m_partType != pt_any && partType == pt_any)
return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance
if (name.empty())
name = m_name;
if (comment.empty())
comment = m_comment;
if (unit.empty())
unit = m_unit;
if (divisor != 0 && divisor != 1)
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
if (!values.empty()) {
NumberDataType* num = (NumberDataType*)m_dataType;
if (values.begin()->first < num->getMinValue() || values.rbegin()->first > num->getMaxValue())
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
}
else
values = m_values;
fields.push_back(new ValueListDataField(name, comment, unit, (NumberDataType*)m_dataType, partType, m_length, values));
return RESULT_OK;
}
示例12: create
result_t SingleDataField::create(const string id, const unsigned char length,
const string name, const string comment, const string unit,
const PartType partType, int divisor, map<unsigned int, string> values,
const string constantValue, const bool verifyValue, SingleDataField* &returnField)
{
DataType* dataType = DataTypeList::getInstance()->get(id, length==REMAIN_LEN ? (unsigned char)0 : length);
if (!dataType) {
return RESULT_ERR_NOTFOUND;
}
unsigned char bitCount = dataType->getBitCount();
unsigned char byteCount = (unsigned char)((bitCount + 7) / 8);
if (dataType->isAdjustableLength()) {
// check length
if ((bitCount % 8) != 0) {
if (length == 0) {
bitCount = 1; // default bit count: 1 bit
} else if (length <= bitCount) {
bitCount = length;
} else {
return RESULT_ERR_OUT_OF_RANGE; // invalid length
}
byteCount = (unsigned char)((bitCount + 7) / 8);
} else if (length == 0) {
byteCount = 1; //default byte count: 1 byte
} else if (length <= byteCount || length == REMAIN_LEN) {
byteCount = length;
} else {
return RESULT_ERR_OUT_OF_RANGE; // invalid length
}
}
if (!constantValue.empty()) {
returnField = new ConstantDataField(name, comment, unit, dataType, partType, byteCount, constantValue, verifyValue);
return RESULT_OK;
}
if (dataType->isNumeric()) {
NumberDataType* numType = (NumberDataType*)dataType;
if (values.empty() && numType->hasFlag(DAY)) {
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
values[numType->getMinValue() + i] = dayNames[i];
}
result_t result = numType->derive(divisor, bitCount, numType);
if (result!=RESULT_OK) {
return result;
}
if (values.empty()) {
returnField = new SingleDataField(name, comment, unit, numType, partType, byteCount);
return RESULT_OK;
}
if (values.begin()->first < numType->getMinValue() || values.rbegin()->first > numType->getMaxValue()) {
return RESULT_ERR_OUT_OF_RANGE;
}
returnField = new ValueListDataField(name, comment, unit, numType, partType, byteCount, values);
return RESULT_OK;
}
if (divisor != 0 || !values.empty()) {
return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field
}
returnField = new SingleDataField(name, comment, unit, (StringDataType*)dataType, partType, byteCount);
return RESULT_OK;
}
示例13: main
int main(){
cin.sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++){
cin >> a[i];
++cnt[a[i]];
}
if(k==1){
auto it = cnt.begin();
cout << it->first;
}else if(k > 2){
auto it = cnt.rbegin();
cout << it->first;
}else{
int lo = 0x3f3f3f3f;
int obest = -0x3f3f3f3f;
for(int i = 0; i < n-1; i++){
lo = min(lo, a[i]);
if(--cnt[a[i]]==0) cnt.erase(a[i]);
auto it = cnt.begin();
int tbest = max(it->first, lo);
obest = max(obest, tbest);
}
cout << obest;
}
}
示例14: main
int main()
{
int n;
while(cin >> n&&n!=0)
{
ans = 0;
int maxx=0;
while(n--)
{
for(int i=0;i<5;i++)
cin >> a[i];
long long int temp = get_tag();
if(ma.find(temp)!=ma.end())
{
ma[temp]++;
}
else ma[temp]=1;
}
map<long long int,int>::iterator ite = ma.begin();
while(ite!=ma.end())
{
if(m.find(ite->second)!=m.end())
m[ite->second]++;
else
m[ite->second]=1;
}
map<int,int>::reverse_iterator ite1 = m.rbegin();
cout <<ite1->second <<endl;
m.clear();
ma.clear();
}
}
示例15: remove
void remove(int n, map<int, int>& small, int& ns, map<int, int>& large, int& nl) {
if(large.find(n) != large.end()) {
del(large, n);
nl--;
} else {
del(small, n);
ns--;
}
if(ns < nl) {
int l = large.begin()->first;
del(large, l);
nl--;
small[l]++;
ns++;
return;
}
if(ns > nl + 1) {
int s = small.rbegin()->first;
del(small, s);
ns--;
large[s]++;
nl++;
return;
}
}