当前位置: 首页>>代码示例>>C++>>正文


C++ map::rend方法代码示例

本文整理汇总了C++中map::rend方法的典型用法代码示例。如果您正苦于以下问题:C++ map::rend方法的具体用法?C++ map::rend怎么用?C++ map::rend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在map的用法示例。


在下文中一共展示了map::rend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
	}
}
开发者ID:dario2994,项目名称:polly,代码行数:28,代码来源:MonomialOrder.hpp

示例2: 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;
}
开发者ID:ctzsm,项目名称:Tsunemori-Akane,代码行数:28,代码来源:298D.cpp

示例3: 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;
}
开发者ID:arnabgho,项目名称:competitive_programming,代码行数:60,代码来源:C_new.cpp

示例4: 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);
}
开发者ID:ctb,项目名称:megahit,代码行数:29,代码来源:assembly_algorithms.cpp

示例5: 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;
}
开发者ID:bingzhangdai,项目名称:zju_pat,代码行数:33,代码来源:1025.+PAT+Ranking.cpp

示例6: run

void run() {
  scanf("%d%d", &n, &m);
  last.clear(); last[m] = 1;
  for (int i = 0; i < n; ++i) {
    int x, s = 0; scanf("%d", &x);
    auto it = last.lower_bound(x);
    for (; it != last.end(); ) {
      last[it->first % x] += it->second;
      s += it->second * (it->first / x);
      it = last.erase(it);
    }
    if (s) last[x - 1] += s;
  }
  int s = 0;
  for (auto it = last.rbegin(); it != last.rend(); ++it) {
    it->second += s; s = it->second;
  }
  int q, ret = 0; scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int x; scanf("%d", &x);
    auto it = last.lower_bound(x);
    if (it != last.end()) ret += 1ll * it->second * i % M;
    if (ret >= M) ret -= M;
  }
  printf("%d\n", ret);
}
开发者ID:KiritoTRw,项目名称:OJ-Problems-Source,代码行数:26,代码来源:3940_csdn.cpp

示例7:

Error::ErrorCode
PotentialManager::populatePotentialsSlimFactors(map<int,SlimFactor*>& factorSet,VSET& varSet)
{
	//The set of flags to keep status of the potentials that have been calculated
	map<int,bool> doneFlag;
	for(map<int,SlimFactor*>::iterator fIter=factorSet.begin();fIter!=factorSet.end();fIter++)
	{
		doneFlag[fIter->first]=false;
	}
	int popFId=0;
	for(map<int,SlimFactor*>::reverse_iterator rIter=factorSet.rbegin();rIter!=factorSet.rend();rIter++)
	{
		//If we have computed the potential for this flag move one
		if(doneFlag[rIter->first])
		{
			popFId++;
			continue;
		}
		SlimFactor* sFactor=rIter->second;
		if(sFactor->fId==176)
		{
			cout <<"Stop here " << endl;
		}
		//Otherwise create the potential
		Potential* aPotFunc=new Potential;
		for(int j=0;j<sFactor->vCnt;j++)
		{
			Variable* aVar=varSet[sFactor->vIds[j]];
			if(j==sFactor->vCnt-1)
			{
				aPotFunc->setAssocVariable(aVar,Potential::FACTOR);
			}
			else
			{
				aPotFunc->setAssocVariable(aVar,Potential::MARKOV_BNKT);
			}
		}
		aPotFunc->potZeroInit();
		populatePotential(aPotFunc,false);
		aPotFunc->calculateJointEntropy();
		sFactor->jointEntropy=aPotFunc->getJointEntropy();
		if(sFactor->jointEntropy<0)
		{
		//	sFactor->jointEntropy=0;
		//	cout <<"Negative entropy for " << sFactor->fId << endl;
		}
		doneFlag[rIter->first]=true;
		delete aPotFunc;
		if(popFId%100000==0)
		{
			cout <<"Done with " << factorSet.size()-popFId << " factors " << endl;
		}
		popFId++;
	}
	return Error::SUCCESS;
}
开发者ID:Roy-lab,项目名称:mrtle,代码行数:56,代码来源:PotentialManager.C

示例8: 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++;		
		}
		
	
}
开发者ID:skash001,项目名称:Graph-partitioning,代码行数:56,代码来源:main.cpp

示例9: conv

string conv(int A){
	string word;
	for(map<int, string>::reverse_iterator it = cvt.rbegin(); it != cvt.rend(); it++){
		while(A >= it->first){
			word += it->second;
			A -= it->first;
		}
	}
	return word;
}
开发者ID:RxFroScarletD,项目名称:Competitive-Programming,代码行数:10,代码来源:759.cpp

示例10: suggestWords

  void suggestWords(){    	
    for ( map<int, vector<string> >::reverse_iterator r = scored_list.rbegin(); r != scored_list.rend(); ++r ) {

      cout << r->first << "\t\t" ;
      for ( string s : r->second ) {
	   cout << s << " " ;
      }
      cout << endl;

    }
  }
开发者ID:jayapradhavr,项目名称:Scrabble,代码行数:11,代码来源:ScrabbleWordSuggestor.cpp

示例11: main

int main()
{
    //pls(palaces 记录地点数目);total,记录学生数目;
    int pls,total=0;
    cin>>pls;
    //base 用于localrank计算。结构为<area,<score,the number of students who have the score> >
    vector<map<int,int> > base(pls);
    for(int i=0;i<pls;i++)
    {
        int stuNums;
        cin>>stuNums;
        total+=stuNums;
        while(stuNums>0)
        {
            string id;
			int score;
            cin>>id>>score;
        //判断local中是否存在此分数,如果不存在,记有此分数的人数为1,否则将人数加1
            if(base[i].find(score)==base[i].end())
                base[i][score]=1;
            else
                base[i][score]++;
            //记录所属area.
            S[score][id]=i+1;
        //    cout<<" .. "<<base[i][score];
        //    cout<<"  SS"<<S[score][id]<<"  "<<endl;
            stuNums--;
        }
    }
    
    for(int j=pls-1;j>=0;j--)
    {
        map<int,int>::reverse_iterator i=base[j].rbegin();
        int lr=0,pre=0;//lr记录前面已经有了多少人,pre起暂存作用。
        for(;i!=base[j].rend();i++)
        {xc
        	pre+=i->second;
            (i->second)=lr+1;
            lr=pre;
        }
    }
    cout<<total<<endl;
    int rank=0;
    for(map<int,map<string,int> >::reverse_iterator i=S.rbegin();i!=S.rend();i++)
    {
        for(map<string,int>::iterator j=(i->second).begin();j!=(i->second).end();j++)
            cout<<j->first<<" "<<rank+1<<" " <<j->second<<" "<<base[j->second-1][i->first]<<endl;
        rank+=(i->second).size();

    }
}
开发者ID:zhangxu999,项目名称:PAT_Alevel,代码行数:51,代码来源:PAT1025_PATRanking.cpp

示例12: _computeS

/**
 * @brief _computeS 
 * back算法配套的排序函数(求出S+集合域), 并求出s
 * @param {map<double, int>} sorted //map遍历,从小到大
 * @param {bulkLink} link //边
 * @param {double} capacity //传输带宽
 * @return {double} 返回计算之后的s
 */
double bulkAgent::_computeS(map<double, int>& sorted, bulkLink link, double capacity)
{
	map<double, int>::reverse_iterator rIter;
	float sum = 0.0, over = 0.0, low = 0.0;
	vector<double> unsearch;
	int* difference = new int[sorted.size()];
	double* demand = new double[sorted.size()];
	int i = 0;
	for (rIter = sorted.rbegin(); rIter != sorted.rend(); rIter++) {
		unsearch.push_back(rIter->first);   //从大到小排序
		int sId = rIter->second;
		difference[i] = link.diffPackets(sId);
		demand[i] = sToDemand[sId];
		i++;
	}
	int lowIndex = 0, highIndex = i - 1, mid = 0;
	while (lowIndex <= highIndex) {  //二分查找法
		mid = lowIndex + ((highIndex - lowIndex) / 2);
		sum = 0.0; 
		float sfake = unsearch.at(mid);
		for (int j = 0 ; j <= mid; j++) {
			float temp = (difference[j] - sfake * pow(demand[j], 2)) / 2;
			if (temp >= 0) {
				sum += temp;
			} else {
				break;
			}
		}
		if (sum < capacity) {
			lowIndex = mid + 1;
		} else if (sum > capacity) {
			highIndex = mid - 1;
		} else {
			break;
		}
	}
	if (sum > capacity) {
		mid = mid - 1;
	} 
	for (int j = 0; j <= mid; j++) {
		over += difference[j];
		low  += pow(demand[j], 2);
	}
	over -= 2 * capacity;
	if (low == 0.0) {
		return 0.0;
	}
	return over/low <= 0.0 ? 0.0 : over/low;
}
开发者ID:Su27SK,项目名称:EventSimualtion,代码行数:57,代码来源:bulkAgent.cpp

示例13: g_if_end_x

ull g_if_end_x(int end_x) {
  int start_x = end_x - (2 * K);
  int floor_sx = MAX_N+2;
  for (map<int, ull>::reverse_iterator j = total_g_at_x.rbegin(); j != total_g_at_x.rend(); j++) {
    int x = j->second;
    if (x < start_x) {
      floor_sx = x;
      break;
    }
  }
  if (floor_sx == MAX_N + 2) {
    return total_g_at_x[end_x];
  } else {
    return total_g_at_x[end_x] - total_g_at_x[floor_sx];
  }
}
开发者ID:zodiac,项目名称:competitive-programming,代码行数:16,代码来源:2_lazy.cpp

示例14: ntreg_init_mapReadFile

bool ntreg_init_mapReadFile(char *filename,struct hive *hdesc)
{
	DWORD dwRead;

	//
	if (!filename) 
	{ 
		return false; 
	}

	//
	hdesc->state = 0;
	hdesc->buffer = NULL;
	hdesc->hFile = NULL;
	hdesc->filename	= str_dup(filename);

	//
	if (*filename == '\\')
	{
		//
		HANDLE hFile = NULL;

		//
		for(map<wstring, HANDLE>::reverse_iterator iter = map2_ntreg.rbegin(); iter != map2_ntreg.rend(); iter++)
		{
			//
			if (_stricmp(common_TCHARToCHAR((LPTSTR)iter->first.c_str()),filename) == 0)
			{
				//
				hFile = iter->second;
				break;
			}
		}

		//
		if (!hFile)
		{
			return false;
		}

		//
		FlushFileBuffers(hFile);

		//
		hdesc->hFile = hFile ;
		hdesc->size = GetFileSize(hFile,NULL);

		//
		HANDLE hMap = CreateFileMapping(hFile,NULL,PAGE_READWRITE,0,0,0);
		//
		if(!hMap) 
		{ 
			return false ; 
		}

		//
		PCHAR pMapView = (PCHAR)MapViewOfFileEx(hMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, NULL);
		//
		if (!pMapView)
		{ 
			return false ;
		}

		hdesc->buffer = pMapView;
		return true ;
	} 
	else
	{
		//
		HANDLE hFile = CreateFileA(hdesc->filename,GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
		//
		if (!hFile) 
		{ 
			return FALSE;
		}

		// Read the whole file
		hdesc->size = GetFileSize(hFile,NULL);
		ALLOC(hdesc->buffer,char,1,hdesc->size);
		//
		ReadFile(hFile, (void *)hdesc->buffer, hdesc->size, &dwRead, NULL);
		CloseHandle(hFile);
		return true;
	}
}
开发者ID:Garfield-Chen,项目名称:openlibs,代码行数:85,代码来源:ntreg_init.cpp

示例15: printGainToCellIdListMap

void printGainToCellIdListMap()
{
   if(gainToCellIdListMap.empty())
   {	
	cout<<"gain bucket empty !!!"<<endl;
	return;		
   }
   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;
   }
 	


}
开发者ID:skash001,项目名称:Graph-partitioning,代码行数:21,代码来源:main.cpp


注:本文中的map::rend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。