Example #1
0
	// Get the top element.
	int top() {
		int result = 0;
		if (!q1.empty()){
			while (q1.size() != 1){
				int tmp = q1.front();
				q1.pop();
				q2.push(tmp);
			}
			result = q1.front();
			q1.pop();
			q2.push(result);
		}
		else{
			if (!q2.empty()){
				while (q2.size() != 1){
					int tmp = q2.front();
					q2.pop();
					q1.push(tmp);
				}
				result = q2.front();
				q2.pop();
				q1.push(result);
			}
		}
		return result;
	}
Example #2
0
/* tournament() encompasses the fighting between the two lineups for the
	tournament. Pits the first Creatures in the queues against each other, and
	puts the winner back in its team's queue and the loser to its team's loser
	stack.
	Input: first team's queue of Creature pointers, first team's stack of loser
		Creature pointers, second team's queue of Creature pointers, second
		team's stack of loser Creature pointers
	Output: none */
void tournament(queue<Creature*>& lineup1, stack<Creature*>& loser1,
	queue<Creature*>& lineup2, stack<Creature*>& loser2)
{
	cout << "Let the tournament begin!" << endl << endl;
	while (lineup1.size() > 0 && lineup2.size() > 0)
	{
		Creature* unit1 = lineup1.front();
		Creature* unit2 = lineup2.front();
		lineup1.pop();
		lineup2.pop();
		/* If I interpreted Uli's post on the Assignment 4 discussion
			correctly, I can statically allocate Creature pointers, which
			is what I'm doing here. The queues were dynamically generated at
			the beginning. */

		combat(unit1, unit2);
		cout << "This round is over!" << endl << endl << endl;

		if (unit1->isAlive())
		{
			lineup1.push(unit1);
			loser2.push(unit2);
		}
		else
		{
			loser1.push(unit1);
			lineup2.push(unit2);
		}
	}
	// // debugging
	// cout << lineup1.size() << " " << lineup2.size() << endl;
	// cout << loser1.size() << " " << loser2.size() << endl;
}
Example #3
0
void initializeStartingCobasis(){

	cout<<"*Max depth of "<<INITDEPTH<<" to initialize starting cobasis list"<<endl;
        if(OUTSTREAM != NULL)
	    OUTSTREAM <<"*Max depth of "<<INITDEPTH<<" to initialize starting cobasis list"<<endl;
	
	//Copy contents of ine file to temporary file	
	copyFile(INPUTFILE, "init_temp.ine");
	ofstream init_temp_file ("init_temp.ine", ios::app);
	init_temp_file<<"maxdepth "<<INITDEPTH<<endl;
	init_temp_file<<"printcobasis 1"<<endl;
	init_temp_file.close();
	boost::thread consumer_init_thread(consumeOutput);
	boost::thread producer_init_thread(findInitCobasis);

	//Wait for producer thread to find all cobasis at depth <= 1
	producer_init_thread.join();
	//Notify init consumer thread that init producer is finished
	notifyProducerFinished();
	//wait for init consumer thread to finish building starting cobasis list
	consumer_init_thread.join();
	//finished initialization starting cobasis array
	initializing = false;
	producers_finished = false;
	cout<<"*Finished initializing cobasis list with "<<cobasis_list.size()<<" starting cobases"<<endl;
        cobasislistsize = cobasis_list.size();
	
}
int Stack::top(){
    if(!q1.empty()){
        while(q1.size() > 1){
            int temp = q1.front();
            q1.pop();
            q2.push(temp);
        }
        int res = q1.front();
        q1.pop();
        q2.push(res);
        return res;
    }
    else if(!q2.empty()){
        while(q2.size() > 1){
            int temp = q2.front();
            q2.pop();
            q1.push(temp);
        }
        int res = q2.front();
        q2.pop();
        q1.push(res);
        return res;
    }
    else
        return -1;
}
Example #5
0
 double next(int val) {
     sum += val;
     q.push(val);
     if (q.size() <= n) {
         return sum / q.size();
     } else {
         sum -= q.front();
         q.pop();
         return sum / n;
     }
 }
 double next(int val) {
     if(myqueue.size() < size) {
         myqueue.push(val);
         sum += val;
     } else {
         myqueue.push(val);
         sum += val;
         sum -= myqueue.front();
         myqueue.pop();
     }
     return sum*1.0/myqueue.size();
 }
Example #7
0
void enablerst::do_update_fps(queue<int> &q, int &sum, int &last, int &calc) {
  while (q.size() > 50 && sum > 10000) {
    sum -= q.front();
    q.pop();
  }
  const int now = SDL_GetTicks();
  const int interval = now - last;
  q.push(interval);
  sum += interval;
  last = now;
  if (sum)
    calc = q.size() * 1000 / sum;
}
int Shop::visitShop(int id)
{
	int retl,retu,cbid;
	 
        retl=pthread_mutex_lock(&lock1);
	if(retl!=0) {
		cout<<"Error:Thread lock failed";
	}
        
        if(f==1) 
        	sem_post(&isleep);
	
	if(waitq.size()==tnc)
	 {
	
		cout<<id<<" Leaves The Shop Because Of No Available Of Waiting Chairs\n";
		nDropsOff++;
		
		pthread_mutex_unlock(&lock1);
		cbid = -1;
		goto retn;			
	 } 
	
	if(!is_Bfree)
	 {
	 	waitq.push(id);
	 	cout<<id<<" Is Waiting in The Chair. # Waiting Seats Available = "<<(tnc-waitq.size())<<"\n";
		
		
                while(!is_Bfree)
                pthread_cond_wait(&wait_chair,&lock1);
	       
	        
                cid=waitq.front();
                
                waitq.pop();
         }
        is_Bfree=0;
        
        cout<<id<<" moves to chair["<<bid<<"]"<<"\n";
        sem_post(&var);
        sem_wait(&busy_barber);
	
	retu=pthread_mutex_unlock(&lock1);
        if(retu!=0) {
		cout<<"Error:Thread lock failed";
        }
        
        cbid=bid;
retn:	return cbid;	
}
int main(){
	freopen("telecow.in", "r", stdin);
	freopen("telecow.out", "w", stdout);
	scanf("%d%d%d%d", &N, &M, &Source, &Sink);
    	while(M--){
       		scanf("%d%d",&x,&y);
		build(x, y);
    	}
	for(int i = 1; i <= N * 2; i++) //复制现场
		for(edge *e = EDGE[i]; e; e = e->next)
			anse[e->x][e->y] = e->cap;
	while(RefreshDistLabel()) FindMaxFlow();
	printf("%lld\n", MAXF = totalflow);
	for(int k = 1; k <= N * 2; k++) //恢复现场
		for(edge *e = EDGE[k]; e; e = e->next)
			e->cap = anse[e->x][e->y];

	for(int i = 1; i <= N; i++){	//枚举每一个点
		if(i == Sink || i == Source) continue;
		for(edge *e = EDGE[i]; e; e = e->next){
			if(e->y - e->x == N){
				temp = e->cap;
				e->cap = 0, totalflow = 0;
				while(RefreshDistLabel()) FindMaxFlow();
				if(totalflow == MAXF - 1){
					anse[e->x][e->y] = 0;
					que.push(i);
					MAXF = totalflow;
					if(MAXF == 0 && que.size()){
						if(que.size()){
							printf("%d", que.front());
							que.pop();
						}
						while(que.size()){
							printf(" %d", que.front());
							que.pop();
						}
						printf("\n");
						return 0;
					}
				}
				for(int k = 1, tot = 0; k <= N * 2; k++) //恢复现场
					for(edge *e = EDGE[k]; e; e = e->next)
						e->cap = anse[e->x][e->y];
			}
		}
	}
	return 0;
}
void V0ToV1AdapterProcess::disconnected()
{
  // Upon noticing a disconnection with the master, we drain the pending
  // events in the queue that were waiting to be sent to the scheduler
  // upon receiving the subscribe call.
  // It's fine to do so because:
  // - Any outstanding offers are invalidated by the master upon a scheduler
  //   (re-)registration.
  // - Any task status updates could be reconciled by the scheduler.
  LOG(INFO) << "Dropping " << pending.size() << " pending event(s)"
            << " because master disconnected";

  pending = queue<Event>();
  subscribeCall = false;

  if (heartbeatTimer.isSome()) {
    Clock::cancel(heartbeatTimer.get());
    heartbeatTimer = None();
  }

  LOG(INFO) << "Disconnected with the Mesos master;"
            << " invoking disconnected callback";

  disconnect();
}
Example #11
0
int main()
{
	int nbcases;
	cin >> nbcases;
	for (int i=0; i<nbcases; i++)
	{
		int n, c, xi, xj;
		cin >> n >> c >> xi >> xj;
		g_n = n;
		g_count = 0;

		g_grille = vector<int>(g_n*g_n, -1);
		g_marques = vector<int>(g_n*g_n, 0);
		for (int j=0; j<g_n*g_n; j++)
			cin >> g_grille[j];

		//test
		//printe(g_grille,g_n);

		g_visit.push(point(xi,xj));
		g_marques[xi*g_n+xj] = 1;
		while (g_visit.size() != 0)
		{
			visiter(g_visit.front());
			g_visit.pop();
			//printe(g_grille, n);
			//sleep(1);
		}

		//printe(g_grille,g_n);
		printf("%d\n", g_count);
	}
}
Example #12
0
void jmxj(wchar_t ch){
    int cond = check_jamo(ch);
    if(cond == JA){
        cout<<"/";
        while (!buf.empty()){
            putwchar(buf.front());
            buf.pop();
        }
        buf.push(ch);
        state = J;
    }
    else if (cond == MO){
        cout<<"/";
        while (buf.size()!=1){
            putwchar(buf.front());
            buf.pop();
        }
        buf.push(ch);
        state = JM;
    }
    else{
        buf.push(ch);
        cout<<"/";
        while (!buf.empty()){
            putwchar(buf.front());
            buf.pop();
        }
        cout<<"/";
        buf.push(ch);
        state = START;
    }
}
Example #13
0
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=0,tmp;i<(n>>1);++i){
        cin>>tmp; xhv[tmp]=1;
        x.push(tmp);
    }
    for(int i=1;i<=n;++i)if(!xhv[i])y.insert(i);
    ll sc=0;
    int lptr=1; while(xhv[lptr])++lptr;
    while(x.size()){
        auto it=y.lower_bound(x.front());
        if(it==y.end()){
            // cout<<"not found"<<endl;
            y.erase(lptr);
            sc-=a[lptr++]; while(xhv[lptr])++lptr;
        }
        else{
            // cout<<"found"<<endl;
            sc+=a[*it];
            xhv[*it]=1;
            y.erase(*it);
        }
        x.pop();
    }
    cout<<sc<<endl;
}
Example #14
0
File: C.cpp Project: S7012MY/Surse
int main() {
  for(cin>>t;t;--t) {
    cin>>n>>m;
    ++n;
    r=(MULT);
    for(int i=0; i<=n; ++i) for(int j=0; j<=n; ++j) dmin[i][j]=(MULT);
    for(int i=0; i<(1<<n); ++i) for(int j=0; j<=n; ++j) bst[i][j]=(MULT);
    for(int i=0; i<m; ++i) {
      int a,b; long long c;
      cin>>a>>b>>c;
      dmin[a][b]=dmin[b][a]=min(dmin[a][b],c);
    }
    for(int k=0; k<n; ++k) for(int i=0; i<n; ++i) for(int j=0; j<n; ++j)
      dmin[i][j]=min(dmin[i][j],dmin[i][k]+dmin[k][j]);
    bst[0][0]=0;
    --n;
    for(c.push(mp(0,0));c.size();c.pop()) {
      int state=c.front().x,lst=c.front().y;
     // cout<<state<<' '<<count(state)<<' '<<lst<<' '<<bst[state][lst]<<'\n';
      int ram=n-count(state);
      if(count(state)==n) {
        r=min(r,bst[state][lst]);
      }
      for(int i=0; i<n; ++i) {
        if(!(state&(1<<i)) && bst[state|(1<<i)][i+1]>bst[state][lst]+ram*1LL*dmin[lst][i+1]) {
          bst[state|(1<<i)][i+1]=bst[state][lst]+ram*1LL*dmin[lst][i+1];
          c.push(mp((state|(1<<i)),i+1));
        }
      }
    }
    if(r==(MULT)) cout<<"-1";
    else cout<<r;
    if(t>1) cout<<'\n';
  }
}
Example #15
0
int main()
{
	//初始化socket,用于tcp网络连接
	WSADATA wsaData;
	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
	{
		return 0;
	}

	// 创建文件夹,保存图片和网页文本文件
	CreateDirectory("./img", 0);
	CreateDirectory("./html", 0);
	//string urlStart = "http://hao.360.cn/meinvdaohang.html";

	// 遍历的起始地址
	string urlStart = "http://www.meitulu.com/";

	// 使用广度遍历
	// 提取网页中的超链接放入hrefUrl中,提取图片链接,下载图片。
	BFS(urlStart);

	// 访问过的网址保存起来
	visitedUrl.insert(urlStart);

	while (hrefUrl.size() != 0)
	{
		string url = hrefUrl.front(); // 从队列的最开始取出一个网址
		cout << url << endl;
		BFS(url);	  // 遍历提取出来的那个网页,找它里面的超链接网页放入hrefUrl,下载它里面的文本,图片
		hrefUrl.pop(); // 遍历完之后,删除这个网址
	}
	WSACleanup();
	return 0;
}
int Translate( string text ){
	int i ;
	int data , value ;
	while(!s.empty())//Initial
	s.pop() ;
	while(!q.empty())
	q.pop() ; 
	for( i = text.length() - 1 ; i >= 0 ; i-- ){
	Push(m[text[i]]) ;
	while(q.size() >= 3){
		data = 0 ;
		for( value = 1 ; value <= 4 ; value *= 2 ){
			if(q.front() == 1)
				data += value ;
				q.pop() ;
		}
			s.push(data) ;
		}
	}
	data = 0 ;
	value = 1 ;
	while( !q.empty() ){
		if( q.front() == 1 )
		data += value  ;
		value *= 2 ;
		q.pop() ;
	}
	s.push(data) ;
}
Example #17
0
 // Push element x onto stack.
 void push(int x) {
     q.push(x);
     for(size_t i = 0; i < q.size() - 1; ++i) {
         q.push(q.front());
         q.pop();
     }
 }
    int top(){
        queue<int> *from;
        queue<int> *to;
        if (q1.size()){
            from = &q1;
        }
        else if(q2.size()){
            from = &q2;
        }
        else{
            cout << "Emtpy Stack!" << endl;
            return 0;
        }

        return from->back();
    }
Example #19
0
static void push_ourlqueue(Url * ourl)
{
    pthread_mutex_lock(&oq_lock);
    ourl_queue.push(ourl);
    if (ourl_queue.size() == 1)
        pthread_cond_broadcast(&oq_cond);
    pthread_mutex_unlock(&oq_lock);
}
Example #20
0
void showMeAdapterSizes(queue <Slav *> queue, stack <Slav *> stack)
{
	printf("[queue_size = %lu, stack_size = %lu, existingSlavs = %i]\n",
		queue.size(),
		stack.size(),
		Slav::counter());

}
 // Push element x onto stack.
 void push(int x) {
     _.push(x);
     for (int i = 0; i < _.size() - 1; i++)
     {
         _.push(_.front());
         _.pop();
     }
 }
Example #22
0
void output_queue(queue <int> Q) {
	int quantity = Q.size(), temp;
	for (int i = 0; i < quantity; i++) {
		temp = Q.front();
		Q.push(temp);
		printf("%d ", temp+1);
		Q.pop();
	}

}
 /** Removes the element on top of the stack and returns that element. */
 int pop() {
     queue<int> tmpQue;
     while(que.size() > 1) {
         last = que.front();
         tmpQue.push(que.front());
         que.pop();
     }
     swap(tmpQue, que);
     return tmpQue.front();
 }
Example #24
0
void push_surlqueue(Surl *url)
{
    if (url != NULL && surl_precheck(url)) {
        SPIDER_LOG(SPIDER_LEVEL_DEBUG, "I want this url: %s", url->url);
        pthread_mutex_lock(&sq_lock);
        surl_queue.push(url);
        if (surl_queue.size() == 1)
            pthread_cond_signal(&sq_cond);
        pthread_mutex_unlock(&sq_lock);
    }
}
Example #25
0
void* dump(void* args){//同步调用处理任务接口
	while(1){
		if(!sourcedata.empty()){
		prodata aaa=sourcedata.front();
		sleep(2);
		cout<<sourcedata.size()<<endl;
		sourcedata.pop();
		receive_data(aaa);
		}
	}
}
Example #26
0
void printHistory(queue<string> printQ) {
    int n = printQ.size();
    for(int i = 0; i < n ; i++) {
        char c = i + 48;
        write(STDOUT_FILENO, &c, 1);
        write(STDOUT_FILENO, " ", 1);
        write(1, printQ.front().data(), printQ.front().length());   //loop should output strings instead of chars when combined with felix
        write(1, "\n", 1);
        printQ.pop();
    }
}
Example #27
0
   // Removes the element on top of the stack.
   void pop() {
	int n = q.size(), temp;
	while(n > 1){
		temp = q.front();
		q.pop();
		q.push(temp);
		t = temp;
		--n;
	}
	q.pop();
   }
Example #28
0
	// Removes the element on top of the stack.
	void pop() {
		if (!q1.empty()){
			while (q1.size()!=1){
				int tmp = q1.front();
				q1.pop();
				q2.push(tmp);
			}
			q1.pop();
		}
		else{
			if (!q2.empty()){
				while (q2.size() != 1){
					int tmp = q2.front();
					q2.pop();
					q1.push(tmp);
				}
				q2.pop();
			}
		}
	}
void Stack::pop(){
    if(!q1.empty()){
        while(q1.size() > 1){
            int temp = q1.front();
            q1.pop();
            q2.push(temp);
        }
        q1.pop();
        return;
    }
    else if(!q2.empty()){
        while(q2.size() > 1){
            int temp = q2.front();
            q2.pop();
            q1.push(temp);
        }
        q2.pop();
        return;
    }
}
 // Removes the element on top of the stack.
 void pop() {
     while( !rse.empty()){
         tmp.push(rse.front());
         rse.pop();
     }
     while(tmp.size()-1 !=0){
         rse.push(tmp.front());
         tmp.pop();
     }
     tmp.pop();
 }