int print_cumulative (deque<double> & kws, string file, int number_of_step) { char buffer [file.size()+1]; cast_string_to_char(file, buffer); ofstream expout (buffer); sort(kws.begin(), kws.end()); int step=(kws.size()-1)/number_of_step; step=max(step, 1); for (int i=0; i<int(kws.size()); i++) if(i%step==0) expout<<kws[i]<<" "<<double(i+1)/(kws.size())<<endl; return 0; }
void iterateDeq(deque<T> &deq) { for(typename deque<T>::iterator dit=deq.begin();dit!=deq.end();dit++) { cout<<*dit<<endl; } }
int main(int argc, char *argv[]) { for(int i=0;i<size;i++) { cin>>frequency[i]; //輸入10個權值 ptr=new node; ptr->key=frequency[i]; ptr->lchild=NULL; ptr->rchild=NULL; forest.push_back(ptr); }//形成森林,森林中的每一棵樹都是一個節點 //從森林構建霍夫曼樹 for(int i=0;i<size-1;i++) { sort(forest.begin(),forest.end(),compare); ptr=new node; //以下代碼使用下標索引隊列元素,具有潛在危險,使用時請注意 ptr->key=forest[0]->key+forest[1]->key; ptr->lchild=forest[0]; ptr->rchild=forest[1]; forest.pop_front(); forest.pop_front(); forest.push_back(ptr); } ptr=forest.front();//ptr是一個指向根的指針 system("PAUSE"); return EXIT_SUCCESS; }
void printDeque(const deque<T>& lst, char *s) { cout << s << ": "; typename deque<T>::const_iterator i = lst.begin(); for ( ; i != lst.end(); i++) cout << *i << ' '; cout << endl; }
ver find (deque <ver> vertex, string name) { for (deque <ver>::const_iterator it=vertex.begin(); it!= vertex.end() ++it) { if (it->name==name) return *it; } }
void Boid::cohesion(deque<Boid*>& neighbours) { Vector2D vForce; float neighborCount = 0; Vector2D vCenterOfMass; deque<Boid*>::iterator itBoid; for(itBoid = neighbours.begin(); itBoid != neighbours.end(); ++itBoid) { if(*itBoid == this) continue; vCenterOfMass.add((*itBoid)->getVelocity()); ++neighborCount; } if(neighborCount > 0) { vCenterOfMass.devide(neighborCount); if(vCenterOfMass.distanceToSQ(getVelocity()) > 5.0f * 5.0f) { Vector2D vel = vCenterOfMass; Vector2D pos = position; pos.normalize(); vel.subtract(pos); vel.subtract(getVelocity()); vel.scale(0.1); velocity.add(vel); } } }
bool Game::getRandomMove(Player p,Game::Move& m) const { deque<Move> moves; // Traverse all the cases... for (Board::ConstStackIterator iter = board_.stacks_begin(), istop= board_.stacks_end(); iter != istop;++iter) { // ... to find a free non empty stack controlled by the player if (iter->hasPieces() && iter->onTop()->color() == colorOf(p) && board_.isFree(iter)) { const deque<Board::ConstStackHandle> poss = possibleDestinations(iter); for (deque<Board::ConstStackHandle>::const_iterator jter = poss.begin();jter!=poss.end();++jter) { moves.push_back(Move(iter.stackCoord(),jter->stackCoord())); } } } if (!moves.empty()) { random_shuffle(moves.begin(),moves.end()); m = moves.front(); return true; } return false; }
int main(int argc, char *argv[]) { for (int i=0;i<size;i++) { cin>>frequency[i]; //?入10??值 ptr=new node; ptr->key=frequency[i]; ptr->lchild=NULL; ptr->rchild=NULL; forest.push_back(ptr); }//形成森林,森林中的每一棵?都是一??? //?森林?建霍夫曼? for (int i=0;i<size-1;i++) { sort(forest.begin(),forest.end(),compare); ptr=new node; //以下代?使用下?索引?列元素,具有?在危?,使用??注意 ptr->key=forest[0]->key+forest[1]->key; ptr->lchild=forest[0]; ptr->rchild=forest[1]; forest.pop_front(); forest.pop_front(); forest.push_back(ptr); } ptr=forest.front();//ptr是一?指向根的指? printCode(code); //system("pause"); while (1); return EXIT_SUCCESS; }
void shuffle_cards() { // Check for clearing cards_.clear(); // Instantiate Deck for(int thirteen = 1; thirteen < 14; thirteen++) { for(int four = 0; four < 4; four++) { card birthCard(thirteen, four); switch(birthCard.value) { case 11: birthCard.value = J; break; case 12: birthCard.value = Q; break; case 13: birthCard.value = K; break; case 1: birthCard.value = A; break; default: // The card was 2-9 break; } cards_.push_back(birthCard); } } random_shuffle(cards_.begin(), cards_.end()); // (cards_.begin(), cards_.end(), mt); }
string getReferenceClass(deque<dtdclass *> & d_Class, string root){//function to find the reference class deque<dtdclass*>::iterator first;/*record the first position of the deque*/ deque<dtdclass*>::iterator last;/*record the last position of the deque*/ first = d_Class.begin();//get the begin of the deque last = d_Class.end();//get the end of the deque if(getISA(d_Class, root, root)==true){/*check the root class have any gener class*/ root = "("+root+")+"; }else{root = root+"+";} for (deque<dtdclass *>::iterator i=first; i !=last;i++){ if(((*i)->getRef())==true && (*i)->getInHeader()==false){ string temp; string ISAname; temp = (*i)->getname(); ISAname = (*i)->getname(); if(getISA(d_Class, temp, ISAname)==true){ root = root + ", (" + ISAname + ")"; /*add the class name in to the string*/ } else{ root = root + ", " + (*i)->getname();/*add the class name in to the string*/ } if((*i)->getlevel()==1){root = root + "+";} else{root = root + "*";} } } return root; }
void printLeaves(int indentSpace, int level, int nodesInThisLevel, const deque<node*>& nodesQueue) { deque<node*>::const_iterator iter = nodesQueue.begin(); for (int i = 0; i < nodesInThisLevel; i++, iter++) { cout << ((i == 0) ? setw(indentSpace+2) : setw(2*level+2)) << ((*iter) ? intToString((*iter)->data) : ""); } cout << "\n"; }
void setReferenceClass(deque<dtdclass *> & d_Class, string className){ deque<dtdclass*>::iterator first;/*record the first position of the deque*/ deque<dtdclass*>::iterator last;/*record the last position of the deque*/ first = d_Class.begin(); last = d_Class.end(); int numberAssoication; for (deque<dtdclass *>::iterator i=first; i !=last;i++){ if((*i)->getname()== className){ if((*i)->getRef() ==true){/*find the match class and the class Ref is true than set it false*/ (*i)->setRef(false); numberAssoication = (*i)->getAssociaAmount(); for(int current=0; current<numberAssoication; current++){/*set all classes relate to this class being the not reference class*/ associate * tempAsso = (*i)->getassociation(current); if(tempAsso->base_Max < 3 || tempAsso->to_Max < 3 ){ string tempAssoname = tempAsso->tclass_name; setReferenceClass(d_Class, tempAssoname);/*to find are there any class have relationship with this class*/ } } for(deque<dtdclass *>::iterator j = first; j!= last; j++) { string belong_to; belong_to = (*j)->getbelong_to(); if(belong_to == (*i)->getname()){/*if the class is belong to the (*i) class, set this class is reference class*/ (*j)->setRef(false); setReferenceClass(d_Class, (*j)->getname());/*to find are there any class is belong to this class*/ } } } } } }
void setGeneralisation(deque<dtdclass *>& d_class, string className, string ISAname){ string tempGeneral,fatherClass; deque<dtdclass*>::iterator first;/*record the first position of the deque*/ deque<dtdclass*>::iterator last;/*record the last position of the deque*/ if(!d_class.empty()){ first = d_class.begin();//get the begin of the deque last = d_class.end();//get the end of the deque for (deque<dtdclass *>::iterator i=first; i!= last;i++){ tempGeneral = (*i)->getname(); if(tempGeneral == className){ (*i)->setbelong_to(ISAname);//set the belong_to class name for(deque<dtdclass *>::iterator j=first; j!= last;j++){ fatherClass = (*j)->getname(); int amountAtt = (*j)->getAttributeAmount(); if(fatherClass == ISAname){//find the class, and get the attribute (*j)->setlevel(1); for(int tempAmount = 0; tempAmount <amountAtt; tempAmount ++){ attribute *newAttribute = (*j)->getattribute(); attribute tempAttribute; strcpy(tempAttribute.att_name, newAttribute->att_name); tempAttribute.isId= newAttribute->isId; tempAttribute.ismulti= newAttribute->ismulti; (*i)->setattribute(tempAttribute);//copy attribute from the "father" to the "son" class } } } } } } }
void analyser::load_data(const deque<char> & buff) { m_pack.clear(); m_pack.insert( m_pack.begin(), buff.begin(), buff.end() ); }
void getFileNames() { DIR *pdir; struct dirent *pent; GLint texsize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texsize); pdir = opendir("venetus"); if(!pdir) { fprintf(stderr,"Failed to open directory. Terminating.\n"); exit(1); } errno = 0; while(pent=readdir(pdir)) { string file = pent->d_name; if(file[0] != '.') { if((file.compare(file.length()-5,5,".surf") == 0) || (file.compare(file.length()-4,4,".obj") == 0)) { if((file.compare(file.length()-8,3,"-lo") == 0) || (file.compare(file.length()-7,3,"-lo") == 0)) { fileNames.push_front(file); } else { fileNames.push_back(file); } } } } if(errno) { fprintf(stderr,"opendir() failed. Terminating.\n"); exit(1); } closedir(pdir); sort(fileNames.begin(),fileNames.end()); }
void ofxBlobTracker::draw(float x,float y,float w, float h) { // stroked rect ofEnableAlphaBlending(); ofSetColor(0, 0, 0, 70); ofRect(x, y, w, h); ofSetHexColor(0xFFFFFF); ofNoFill(); ofRect(x, y, w, h); glPushMatrix(); glTranslatef(x, y, 0); ofSetColor(0,150, 0); map<int,ofVec3f>::iterator it; for(it = smoothedBlobs.begin(); it!=smoothedBlobs.end(); it++) { ofCircle((*it).second.x*w, (*it).second.y*h, 5); ofDrawBitmapString("id: "+ofToString((*it).first), (*it).second.x*w, (*it).second.y*h); blobStore.push_back((*it).second); } while(blobStore.size()>50) { blobStore.pop_front(); } deque<ofVec2f>::iterator itr; for(itr = blobStore.begin(); itr!=blobStore.end(); itr++) { ofCircle((*itr).x*w,(*itr).y*h, 5); } glPopMatrix(); ofFill(); }
void mythread_exit() { tcb *this_th = thread_list[this_th_th]; while (!this_th->waiting.empty()) { queue.push_back(this_th->waiting.front()); this_th->waiting.pop_front(); } deque<tcb*>::iterator it = find(queue.begin(), queue.end(), this_th); if (it != queue.end()) queue.erase(it, it+1); if (queue.empty()) { exit(0); // no other thread remaining } // run the next thread if availiable tcb * thread = queue.front(); queue.pop_front(); tcb *th = thread_list[this_th_th]; delete th; thread_list.erase(this_th_th); this_th_th = thread->id; setcontext(&(thread->context)); }
string print() { stringstream ss; deque<d_t>::iterator it; for(it = number.begin(); it != number.end(); it++) ss << (*it); return(ss.str()); }
void DeleteVip() { cin.get(); size_t i; string studentId; cout << endl; cout << "********************************************************" <<endl; cout << "* Delete vip by number... *" <<endl; cout << "********************************************************" <<endl; cout << "Please input student Id(string): "; cin >> studentId; for(i = 0; i < vip.size(); i++) { pVip = vip[i]; if(0 == studentId.compare(pVip->GetStudentId())) { cout << endl; pVip->DisplayInfo(); pVip->DisplayOtherInfo(); pVip = 0; vip.erase(vip.begin() + i); cout << "********************************************************" <<endl; cout << "* Finished to delete... *" <<endl; cout << "********************************************************" <<endl; return; } } cout << "********************************************************" <<endl; cout << "* Can't find vip... *" <<endl; cout << "********************************************************" <<endl; }
void convexHull4d::getHorizonRidges(deque<long>& horizonRidges, vertex4d* furthest) { for(deque<long>::iterator fit = furthest->getVisibleFacets().begin(); fit!=furthest->getVisibleFacets().end(); fit++) { deque<long>::iterator rit; for(rit = tempFacets.find((*fit))->second.getContaining2dSimplices().begin() ; rit!=tempFacets.find((*fit))->second.getContaining2dSimplices().end(); rit++) { bool isFirstNeighbour = tempRidges.find((*rit))->second.getNeighbour1()==(*fit); long neigh; if(isFirstNeighbour) neigh = tempRidges.find((*rit))->second.getNeighbour2(); else neigh = tempRidges.find((*rit))->second.getNeighbour1(); if(find(furthest->getVisibleFacets().begin(),furthest->getVisibleFacets().end(),neigh)==furthest->getVisibleFacets().end() && find(horizonRidges.begin(), horizonRidges.end(),*rit)==horizonRidges.end()) { horizonRidges.push_back(*rit); if(isFirstNeighbour) tempRidges.find((*rit))->second.setNeighbour1(0); else tempRidges.find((*rit))->second.setNeighbour2(0); } } } }
bool isDivByEleven(const deque<unsigned int>& number){ if (number.size() == 1){ if (number[0] == 0) return true; else return false; } bool isOdd = true; deque<unsigned int> odd; deque<unsigned int> even; for (deque<unsigned int>::const_iterator itr = number.begin(), endItr = number.end() ; itr != endItr; itr++, isOdd = !isOdd) { unsigned int digit = *itr; if (isOdd) vecSum(odd, digit); else vecSum(even, digit); } deque<unsigned int> diff; if (isBigger(odd, even)) vecDiff(odd, even, diff); else vecDiff(even, odd, diff); if (isDivByEleven(diff)) return true; return false; }
int main() { scanf("%d%d", &n, &m); for(int i = 1; i <= n; i ++) { scanf("%d", &a[i]); v[i] = a[i]; } for(int i = 1; i <= m; i ++) v[n + i] = i; sort(v + 1, v + n + m + 1); int len = unique(v + 1, v + n + m + 1) - v - 1; for(int i = 1; i <= n; i ++) a[i] = lower_bound(v + 1, v + len + 1, a[i]) - v; int num = n / m; printf("%d ", num); for(int i = 1; i <= n; i ++) { if (a[i] <= m) cnt[a[i]] ++; else can.push_back(make_pair(a[i], i)); if (cnt[a[i]] > num) can.push_back(make_pair(a[i], i)); } sort(can.begin(), can.end()); int sum = 0; for(int i = 1; i <= m; i ++) { while(cnt[i] < num) { int t = can.back().second; can.pop_back(); a[t] = i; sum ++; cnt[i] ++; } } printf("%d\n", sum); for(int i = 1; i <= n; i ++) printf("%d%c", v[a[i]], i == n ? '\n' : ' '); return 0; }
Solver(int num): n(num){ vector<int> arr(n); for(int i=0;i<n;++i){ scanf("%d",&arr[i]); } scanf("%d %d",&p,&q); left=0;right=INT_MAX; for(int i=0;i<n;++i){ if(arr[i]>=p && arr[i]<=q){ numList.push_back(arr[i]); } left = (arr[i]<p && arr[i]>left) ? arr[i] : left ; right = (arr[i]>q && arr[i]<right) ? arr[i] : right ; } if(debug)cout<<"left:"<<left<<" right:"<<right<<endl; if(left!=0){ numList.push_back(left); } if(right!=INT_MAX){ numList.push_back(right); } sort(numList.begin(),numList.end()); }
// LOGIC: if there's still stuff on the queue, // we pop one vertex*, then check it to see if it's the destination // if yes, we are done (return true) // if no, we push all its unvisited neighbor vertex* on the queue // for each neighbor, we store a pointer to the vertex* we came from // and then return the result of breadth first search again. // If the queue is empty, we give up (return false) bool graph::breadth_first_search(vertex* u, map<vertex*, bool>& visited, deque<vertex*>& yet_to_explore, map<vertex*, vertex*>& path) { if (!yet_to_explore.empty()) { //grab the last item in the deque vertex* b = yet_to_explore.front(); //grab first entry use .front() //pop this item off yet_to_explore.erase(yet_to_explore.begin()); //if that item is u, were' done (our base case) if(b->get_city_name() == u-> get_city_name()) { return true; } vector<vertex*>::iterator it; for(it = edges[b].begin(); it != edges[b].end(); ++it) { vertex* neighbor = *it; if(visited[neighbor] == false) { yet_to_explore.push_back(neighbor); visited[neighbor] = true; path[neighbor] = b; // we came from w to get to neighbor } } return depth_first_search(u, visited, yet_to_explore, path); } else return false; }
bool isReady(const Microop &pInstr, int *scoreboard, deque<Microop> &ROB) { //exp1 requirement if (pInstr.arch_src1 != -1 && scoreboard[pInstr.phys_src1] != 0) return false; if (pInstr.arch_src2 != -1 && scoreboard[pInstr.phys_src2] != 0) return false; if (pInstr.readFlag == 1 && scoreboard[pInstr.flag_phys_ex] != 0) return false; //exp2 requirement if (pInstr.is_load == 1) { deque<Microop>::iterator it; for (it = ROB.begin(); it != ROB.end(); ++it) if ((*it).is_store == 1 && (*it).numMicro < pInstr.numMicro && !((*it).issued ==1 && (*it).done_cycle <= totalCycle)) { //exp3 requirement if ((*it).mem_op_addr == pInstr.mem_op_addr) return false; } } return true; }
static void print_result(deque<int> &ret) { for (auto it = ret.begin(); it != ret.end(); it++) { cout << *it << " "; } cout << endl; }
bool levelCheck(deque<TreeNode*> lv) { if (lv.empty()) return true; deque<TreeNode*>::iterator l = lv.begin(); deque<TreeNode*>::iterator r = lv.end()-1; deque<TreeNode*> ret; while(l<r) { if(*l == NULL && *r==NULL) { l++; r--; } else if (*l==NULL || *r==NULL) { return false; } else { if((*l)->val != (*r)->val) return false; else { ret.push_front((*l)->right); ret.push_front((*l)->left); ret.push_back((*r)->left); ret.push_back((*r)->right); l++; r--; } } } return levelCheck(ret); }
void addQueue(Bottle& status) { status.add(Value::makeVocab("q")); for (deque<Entry>::iterator it=q.begin(); it!=q.end(); it++) { string name = (*it).name; status.addString(name.c_str()); } }
// Print the leaves only (just for the bottom row) void printLeaves(int indentSpace, int level, int nodesInThisLevel, const deque<BinaryTree*>& nodesQueue, ostream& out) { deque<BinaryTree*>::const_iterator iter = nodesQueue.begin(); for (int i = 0; i < nodesInThisLevel; i++, iter++) { out << ((i == 0) ? setw(indentSpace+2) : setw(2*level+2)) << ((*iter) ? intToString((*iter)->data) : ""); } out << endl; }
void add_node(deque<node>& dq, const node& nd) { // if position is not valid for the matrix - return if (!is_position_valid(nd._r, nd._c)) return; // check the cell - can we step on it? if (arr[nd._r][nd._c] == -1) return; // check if the node is already added once to the deque // this use the operator==(const node& lhs, const node& rhs) if(find(dq.begin(), dq.end(), nd) != dq.end()) return; // check if the cell was visited before. if(position_visited[nd._r][nd._c] == 1) return; // add node to deque dq.push_back(nd); // mark position as visited mark_pos_visited(nd._r, nd._c); }