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; } }
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; }
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; }
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); }
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; }
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); }
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; }
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++; } }
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; }
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; } }
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(); } }
/** * @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; }
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]; } }
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; } }
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; } }
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; } }
void convertCommodityMapToCommodotyList(vector<commodity>& commodity_list, const map<string, double>& commodity_map) { discountControl discount_instance = discountControl::getInstance(); barCodeControl cashier_instance = barCodeControl::getInstance(); commodity_info goods_info = {}; DISCOUNTTYPE discout_type = NoDiscount; for(map<string, double>::const_reverse_iterator const_itor = commodity_map.rbegin(); const_itor!= commodity_map.rend(); const_itor++) { discout_type = discount_instance.getDiscountType(const_itor->first); cashier_instance.getCommodityInfo(const_itor->first, goods_info); goods_info.number = const_itor->second; commodity commodity_item(goods_info.number, goods_info.name, goods_info.price, goods_info.unit,discout_type); commodity_list.push_back(commodity_item); } }
//复制hive文件句柄到本地进程 bool ntreg_init_getDuplicateHandle(PSYSTEM_HANDLE_INFORMATION pSystem_handle_information,DWORD dwSystemPID,DWORD dwFileObjectTypeNumber,map<wstring, wstring> &map_,map<wstring, HANDLE> &map2_) { // HANDLE hRet = NULL; // HANDLE hSystemProcess = OpenProcess(PROCESS_DUP_HANDLE,FALSE,dwSystemPID); // if(!hSystemProcess) { // return false; } // HANDLE hCurrentHandle = GetCurrentProcess(); // for(int i = 0; i < pSystem_handle_information->NumberOfHandles; i++) { // if (pSystem_handle_information->Information[i].UniqueProcessId == dwSystemPID && dwFileObjectTypeNumber == pSystem_handle_information->Information[i].ObjectTypeIndex) { // if (!DuplicateHandle(hSystemProcess,(HANDLE)pSystem_handle_information->Information[i].HandleValue, hCurrentHandle,&hRet,0,FALSE,DUPLICATE_SAME_ACCESS)) { // continue; } // TCHAR tmpName[4096] = { 0 }; // PUNICODE_STRING pObjectName = (PUNICODE_STRING)ntreg_init_getFileObjectName(hRet); // if (!pObjectName) { // continue; } // if (pObjectName->Length != 0) { // for(map<wstring, wstring>::reverse_iterator iter = map_.rbegin(); iter != map_.rend(); iter++) { // if (_wcsicmp(iter->second.c_str(),pObjectName->Buffer) == 0) { // map2_.insert(map<wstring, HANDLE>::value_type(iter->first,hRet)); } } } // free(pObjectName); } } // CloseHandle(hSystemProcess); return true; }
/** Returns one of the keys with maximal value. */ string getMaxKey() { auto it = cnts.rbegin(); if (it == cnts.rend()) return ""; return *it->second.begin(); }
int main(int argc, char *argv[]){ istream *br; ifstream infile; //Opening file if (argc==1){ br = &cin; } else if(argc == 2) { //must have at least 3 arguments infile.open(argv[1]); if(infile.is_open()){ br = &infile; } else{ usage(argv[0], "Cannot open " + string(argv[1])); return 1; } } else { usage(argv[0], "Too many command line arguments."); return 1; } if(!(br->good())){ usage(argv[0], "I could not read your file :/"); return 1; } Token token; string lex; vector<string> identifiers; //Calling getToken() while (true){ token = getToken(br, lex); counters[token]++; if (token == ID){ if (identifiers.empty() || find(identifiers.begin(), identifiers.end(), lex) == identifiers.end()){ identifiers.push_back(lex); } } else if (token == DONE){ break; } else if (token == ERR){ cout << "Error on line " << linenum <<endl; return 1; } } //iterate through counters, append Tokens to list at int of Tokens key map<Token, int>::iterator it; for(it=counters.begin(); it != counters.end(); it++){ bycount[it->second].push_back(it->first); } //iterate backward through bycount, output top 3 Tokens map< int, vector<Token> >::reverse_iterator it2; int limit=0; for (it2=bycount.rbegin(); it2 != bycount.rend(); it2++){ limit ++; for (int x=0; x< it2-> second.size(); x++){ Token token = it2->second[x]; if (token == ID){ cout << "Identifier: "; } else if (token == STRING){ cout << "String constant: "; } else if (token == UNION){ cout << "Union operator: "; } else if (token == INTERSECT){ cout << "Intersect operator: "; } else if (token == SET){ cout << "SET keyword: "; } else if (token == PRINT){ cout << "PRINT keyword: "; } else if (token == SEARCH){ cout << "SEARCH keyword: "; } else if (token == FOR){ cout << "FOR keyword: "; } else if (token == LPAREN){ cout << "Left paren: "; } else if (token == RPAREN){ cout << "Right paren: "; } else if (token == SC){ cout << "Semicolon: "; } if (token != DONE){ cout << it2->first <<endl; } } //Print only top 3 if (limit > 2){ break; } } //output identifiers if there are any if (identifiers.size() != 0){ <<<<<<< Updated upstream cout << "List of identifiers: "; for (int x = 0; x < identifiers.size(); x++){ if (x==identifiers.size()-1){ cout << identifiers[x]; ======= cout << endl; int index=0; cout << "List of identifiers: "; map<string, int>::iterator it3; for (it3 = identifiers.begin(); it3 != identifiers.end(); it3++){ index++; if (index == identifiers.size()){ cout << it3-> first << endl; >>>>>>> Stashed changes } else {