Example #1
0
	void update() {
		const ofVec3f &p = joint->getPosition();
        
        if (points.size() == 0 || p.distance(points.front()) > 1) {
            points.push_front(joint->getPosition());
        }

        if (points.size() > trackerLength){
			points.pop_back();
		}
	}
Example #2
0
    void nextRound() {
        int winner = order_.back();
        pot_.remove();
        hands_[winner].add(pot_);
        pot_.clear();

        while (!passed_.empty()) {
            order_.push_front(passed_.back());
            passed_.pop_back();
        }
    }
Example #3
0
 void update(ofVec3f _pos) {
     ofVec3f p = _pos;
     
     //if (p.distance(points.front()) > 1){
     points.push_front(p);
     //}
     
     if (points.size() > trackerLength){
         points.pop_back();
     }
 }
Example #4
0
void TopSorter::recursiveTopSort(Vertex *v, deque<Vertex *> &s)
{
	v->setVisited(true);
	Vertices *adjacent = v->getAdjacent();
	for (Vertex *a : *adjacent) {
		if (!a->isVisited()) {
			recursiveTopSort(a, s);
		}
	}
	s.push_front(v);
}
Example #5
0
	void update()
	{
		// 軌跡を追加
		if ((line_strip.front() - pos).lengthSquared() > 60)
		{
			line_strip.push_front(pos);
		}
		
		// 長くなりすぎた軌跡を削除
		if (line_strip.size() > 300) line_strip.pop_back();
	}
void enqueue(int u, int v, int previous_cost, int edge_cost, deque< pair<int, int> > &q) {
    printf("   trying to push (%d, %d) with cost %d (current cost is %d)\n", u + 1, v + 1, previous_cost + edge_cost, d[u][v]);
    if (d[u][v] == -1 or previous_cost + edge_cost < d[u][v]) {
        d[u][v] = previous_cost + edge_cost;
        assert(edge_cost == 0 or edge_cost == 1);
        if (edge_cost == 0) q.push_front(make_pair(u, v));
        else q.push_back(make_pair(u, v));
        
        printf("     pushed (%d, %d) with cost %d\n", u + 1, v + 1, d[u][v]);
    }
}
Example #7
0
void Solver::minimizeAndStoreUIPClause(LiteralID uipLit,
		vector<LiteralID> & tmp_clause, bool seen[]) {
	static deque<LiteralID> clause;
	clause.clear();
	assertion_level_ = 0;
	for (auto lit : tmp_clause) {
		if (existsUnitClauseOf(lit.var()))
			continue;
		bool resolve_out = false;
		if (hasAntecedent(lit)) {
			resolve_out = true;
			if (getAntecedent(lit).isAClause()) {
				for (auto it = beginOf(getAntecedent(lit).asCl()) + 1;
						*it != SENTINEL_CL; it++)
					if (!seen[it->var()]) {
						resolve_out = false;
						break;
					}
			} else if (!seen[getAntecedent(lit).asLit().var()]) {
				resolve_out = false;
			}
		}

		if (!resolve_out) {
			// uipLit should be the sole literal of this Decision Level
			if (var(lit).decision_level >= assertion_level_) {
				assertion_level_ = var(lit).decision_level;
				clause.push_front(lit);
			} else
				clause.push_back(lit);
		}
	}

	if(uipLit.var())
	 assert(var(uipLit).decision_level == stack_.get_decision_level());

	//assert(uipLit.var() != 0);
	if (uipLit.var() != 0)
		clause.push_front(uipLit);
	uip_clauses_.push_back(vector<LiteralID>(clause.begin(), clause.end()));
}
 void noOperand(string& opCode)
 {
   double result;
        if(opCode == "pi") result = M_PI;
   else if(opCode == "e")  result = M_E;
   else {
     cout << "unknown operator " << opCode.c_str() << endl;
     return;
   }
   cout << result << endl;
   s.push_front(result);
 }
Example #9
0
void initStep(Xpp *xpp) {
    int N; Window* win; tie(win,N) = xpp->getWindows();
    for(int i=0; i<N; i++) {
        if(xpp->isAWindow(win[i])) {
            windows.push_front  (win[i]);
            xpp->resizeAndCenter(win[i], minW, minH);
            XImage* image       = xpp->getImage(windows.front());
            if(image)           draw->add(windows.front(), image->data, (xpp->width-minW)/2, (xpp->height-minH)/2, image->width, image->height);
        }
    }
    XFree(win);
}
int choose(deque<int> de)
{
	void display(deque<int>, int);
	int temp;   
	char c; 
	int cal_num = 0;    // To calculate the size of the front stack. 
	
	cout<<"Option: 1-push from the front, 2-push from the back,\n"
	 	<<"        3-pop from the front, 4-pop from the back,\n"
	  	<<"        5-display the doublestack, #-quit.\n";  
	while(1){   
		cout<<"Input the option£º";   
		cin>>c;   
		switch(c)
		{    
			// push from the front
			case'1':cout<<"Input the element£º";     
					cin>>temp;    
					de.push_front(temp);
					cal_num++;
					break;
			// push from the back
			case'2':cout<<"Input the element£º";    
					cin>>temp;    
					de.push_back(temp);
					break;
			// pop from the front
			case'3':if (cal_num > 0){
						cal_num--; 
						de.pop_front();
						cout<<"popped from the front!\n";
					}
					// if there is no data, don't change cal_num and de.
					else	
						cout<<"Front Stack empty!\n";  	
					break;
			// pop from the back
			case'4':if (de.size()-cal_num > 0){
						de.pop_back();
						cout<<"popped from the back!\n";
					}
					// if there is no data, don't change de.
				 	else
				 		cout<<"Back Stack empty!\n";
					break;
			// display all the elements in the doublestack
			case'5':display(de, cal_num);
					break;
			case'#':return 0;
			default:cout<<"Error input! Please try again."<<endl;
		}    
	}  	
}
Example #11
0
int main(){

    while (~scanf("%d", &n)) {
        idx = 0;
        vt.clear();
        for (int i = 0; i < n; ++i) {
            scanf("%d", &cmd[i]); 
            if (!cmd[i]) {
                ++idx;
            } else { 
                vt.push_back((Node){cmd[i], i, idx}); 
            }
        }

    
        sort(vt.begin(), vt.end());
        memset(vis, 0, sizeof(vis));
        memset(cnt, 0, sizeof(cnt));

        init();
        for (int i = 0; i < vt.size(); ++i) {
            for (int j = vt[i].belong; j < idx; j = find(j+1)) {
                if (cnt[vt[i].belong] < 3) {
                    vis[vt[i].id] = true;
                    ++cnt[vt[i].belong];
                    break;
                } else {
                    f[j] = j + 1; 
                }
            }
        }

        while (!st.empty()) st.pop();
        while (!que.empty()) que.pop();
        while (!que.empty()) dq.pop_front();

        addNum = 0, outNum = 0;
        for (int i = 0; i < n; ++i) {
            if (cmd[i]) {
                if (vis[i]) {
                    add(cmd[i]); 
                } else {
                    dq.push_front(i);
                    puts("pushBack");
                }
            } else {
                output();
            }
        }
    }
    return 0;
}
void producer(int id) {
    unique_lock<mutex> locker(mu, defer_lock); 
    for(int i = 0; i < LIMIT + 1; ++i) {
        locker.lock();
        cout << "producer: " << id << endl;
        d.push_front(i);
        if(i == LIMIT)
            ++_is_done;
        locker.unlock();
        std::this_thread::sleep_for(std::chrono::milliseconds(5));    
        cond.notify_all();
    }
}
// Shrinks one side of a blossom.
void shrink_one_side(int x, int y, int b){
  blossoms++;
  for (int i=f(x); i!=b; i=f(p[i])) {
    u(i, b);
    if (d[i]==1) { 
      c1[i]=x;
      c2[i]=y;
      // All nodes in blossom are reachable an even 
      // distance from the root, so push onto queue.
      q.push_front(i); // *qb++=i;  
    }
  }
}
int main(){
    int T;
    freopen("cubes.in","r",stdin);
    cin>>T;
    for(int cas=1;cas<=T;cas++){
        int n;
        cin>>n;
        for(int i=0;i<n;i++) cin>>a[i];
        sort(a,a+n);
        q.clear();
        q.push_front(a[0]);
        if(n&1){
            for(int i=1;i<n;i++){
                if(i&1) q.push_front(a[i]);
                else q.push_back(a[i]);
            }
        }
        else{
            for(int i=1;i<n;i++){
                if(i&1) q.push_back(a[i]);
                else q.push_front(a[i]);
            }
        }
        deque<int>::iterator it=q.begin();
        v.clear();
        while(it!=q.end()){
            v.push_back(*it);
            it++;
        }
        printf("Case %d:\n",cas);
        for(int i=0;i<v.size();i++){
            printf("%d",v[i]);
            if(i+1==v.size()) printf("\n");
            else printf(" ");
        }
    }
    return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&element[i].value);
        element[i].position=i;
    }
    for(int i=0;i<n;i++)
    {
        while(!getMin.empty() && element[i].value<getMin.front().value)
        {
            getMin.pop_front();
        }
        getMin.push_front(element[i]);
        if(i-getMin.back().position>=k)
        {
            getMin.pop_back();
        }
        if(i>=k-1 && i<n-1) printf("%d ",getMin.back());
    }
    printf("%d\n",getMin.back());
    for(int i=0;i<n;i++)
    {
        while(!getMax.empty() && element[i].value>getMax.front().value)
        {
            getMax.pop_front();
        }
        getMax.push_front(element[i]);
        if(i-getMax.back().position>=k)
        {
            getMax.pop_back();
        }
        if(i>=k-1 && i<n-1) printf("%d ",getMax.back());
    }
    printf("%d\n",getMax.back());
    return 0;
}
Example #16
0
    void update()
    {
	   if (joint->getBvh()->isFrameNew())
		{
			const ofVec3f &p = joint->getPosition();

			points.push_front(joint->getPosition());

			if (points.size() > 15)
				points.pop_back();
		}


    }
Example #17
0
void pick(int i, int j)
{
	if (i <= 0 || j <= 0) return;

	int k = DP[i][j];
	if (k != DP[i - 1][j]) {
		selected.push_front(i);
		// item is selected, capacity decreases
		pick(i - 1, j - tda[i]);
	} else {
		// move on to next item; capacity no change
		pick(i - 1, j);
	}
}
Example #18
0
    void orderByDriver(deque<string>& ports, deque<string>& drivers,
                       const char* driver_name,
                       bool all_ports)
    {
        if (ports.empty()) {
            return;
        }

        vector<string>::const_iterator it =
            std::find(driver_names_.begin(), driver_names_.end(), driver_name);
        if (it != driver_names_.end()) {
            ports.push_front(ports.back());
            ports.pop_back();

            drivers.push_front(drivers.back());
            drivers.pop_back();

        } else {
            if (! all_ports) {
                ports.pop_back();
                drivers.pop_back();
            }
        }
    }
Example #19
0
void vecSum (deque<unsigned int>& number , unsigned int summand){
  if (number.empty())
    number.push_back(0);
  unsigned int carry = summand;
  for (deque<unsigned int>::reverse_iterator itr = number.rbegin(), endItr = number.rend(); carry > 0 && itr != endItr; itr++){
    int sum = *itr + carry;
    *itr = sum % 10;
    carry = sum / 10;
  }

  while (carry > 0){
    number.push_front(carry%10);
    carry /= 10;
  }
}
Example #20
0
main()
{
    scanf("%d%s",&n,s) ;
    for(int i=0;i<n;i++)
    {
        if(v.empty()){v.push_back(s[i]) ; R() ; continue ;}
        if(s[i]==v.front()) v.pop_front() , L() ;
        else if(s[i]==v.back()) v.pop_back() , R() ;
        else if(v.size()==1) v.push_back(s[i]) , R() ;
        else if(i==n-1 || (i!=n-1 && s[i+1]==s[i]))
            v.push_back(s[i]) , R() ;
        else if(s[i+1]==v.back()) v.push_front(s[i]) , L() ;
        else v.push_back(s[i]) , R() ;
    }
    printf("\n") ;
}
Example #21
0
int test()
{
	int v;
	if(q.size()<2)
		return 0;
	t=q.front();
	q.pop_front();
	s=q.front();
	v=(t.x-s.x)*(cnt.y-s.y)-(cnt.x-s.x)*(t.y-s.y);
	if(v>0)
	{
		q.push_front(t);
		return 0;
	}
	return 1;
}
Example #22
0
void bfs(piii an) {
    mark[an.L][an.R.L][an.R.R] = true;
    Q.push_back(an);
    while(Q.size()) {
        int x = Q.front().L, y = Q.front().R.L, z = Q.front().R.R;
        Q.pop_front();
        for(auto u : adj2[x][y][z]) if(!mark[u.L.R][u.R.L][u.R.R]) {
                mark[u.L.R][u.R.L][u.R.R] = true;
                dis[u.L.R][u.R.L][u.R.R] = dis[x][y][z] + u.L.L;
                if(u.L.L == 0)
                    Q.push_front(MP(u.L.R, u.R));
                else
                    Q.push_back(MP(u.L.R, u.R));
            }
    }
}
Example #23
0
//здесь просто добавляем единицу:
deque<int> Converter::add_one(deque<int> op) {
    for(int i=op.size()-1; i >= 0; i--) {
        if((int)op[i] == 0) {
            op[i] = 1;
            break;
        } else {
            op[i] = 0;
            if(i==0) {
                op.push_front(1);
                break;
            }
        }
    }
    
    return op;
}
Example #24
0
int main(int argc, char *argv[])
{
    setIO("tower");
    n = gi;
    for(int i = 1;i<=n;++i)
     a[i] = gi;
    for(int i = 1;i<=n+1;++i)
     a[i] = a[i-1]+a[i];
    q.push_front(n+1);
    for(int i = n;i>=0;--i)
    {
     while(!q.empty())
     {
      int x = q.front();q.pof();
      if(q.empty()){
       q.pf(x);
       break;
      }else{
       int y = q.front();q.pof();
       if(a[x] >= a[y] && a[i]<=a[y]-f[y])
        q.pf(y);
       else
       { 
       q.pf(y),q.pf(x);
       break;
       }
      }
     }
     f[i] = a[q.front()]-a[i];
     h[i] = h[q.front()]+1;
     ans = max(ans,h[i]);
     while(!q.empty()){
      int x = q.back();q.pob();
      if(a[x]-f[x] < a[i]-f[i] && a[x]>=a[i] )
       continue;
      else{
       q.pb(x);
       break;
      }
     }
     q.pb(i);
    }
    printf("%d\n",ans-1);
    closeIO();
    return EXIT_SUCCESS;
}
Example #25
0
bool solve_problem(int n, int c)
{
	bool is_front = true;
	(void) c;

	for (int i = 0; i < n; i++)
		if (op[i] == -1) {
			is_front = !is_front;
		} else {
			if (is_front)
				books.push_front(op[i]);
			else
				books.push_back(op[i]);
		}

	return is_front;
}
Example #26
0
    int sumNumbersHelper2(TreeNode* root, deque<int> prefix)
    {
    	if (root == NULL)
    		return 0;
    	prefix.push_front(root->val);

    	if (root->left == NULL and root->right == NULL)
    	{
    		int sum = 0;
    		int level = 0;
    		for (auto i : prefix)
    			sum += i * pow(10, level++);
    		return sum;
    	}

    	return sumNumbersHelper2(root->left, prefix) + sumNumbersHelper2(root->right, prefix);
    }
Example #27
0
bool modlabel()
{
    static int d[N]; memset(d, 0x3F, sizeof(d)); d[T] = 0;
    static deque<int> Q; Q.push_back(T);
    while(Q.size())
    {
        int dt, no = Q.front(); Q.pop_front();
        for(Edge *i = e[no]; i; i = i->next)
            if(i->pair->c && (dt = d[no] - i->u) < d[i->t])
                (d[i->t] = dt) <= d[Q.size() ? Q.front() : 0]
                    ? Q.push_front(i->t) : Q.push_back(i->t);
    }
    for(int i = 0; i < n; ++i)
        for(Edge *j = e[i]; j; j = j->next)
            j->u += d[j->t] - d[i];
    piS += d[S];
    return d[S] < INF;
}
Example #28
0
    void aux(int s, int e) {
        stk.push_front(s);
        if (s == 0) {
            now.clear();
            now += cs.substr(stk[0], stk[1]);
            for (int j = 1; j < stk.size() - 1; j++) {
                now.push_back(' ');
                int t1 = stk[j], t2 = stk[j + 1] - t1;
                now += cs.substr(t1, t2);
            }
            res.push_back(now);
        } else {
            for (auto& i : vec[s]) {
                aux(i, s);
            }
        }

        stk.pop_front();
    }
Example #29
0
// this function push numbers in a queue and sleep for a second.
void function01()
{
    int count = 10;
    while(count > 0)
    {
        unique_lock<mutex> locker(mu);
        q.push_front(count);
        locker.unlock();
        cond.notify_one(); 
        /*
        there is only one thread/condition who is waiting. for thread 1. but there could be many 
        thread condition who will be waiting for threas 1 (or any thread). that time we can use 
        below mentioned function.
        cond.notify_all(); 
        that will wake up all the threads.
        */
        std::this_thread::sleep_for(chrono::second(1));
        count--;
    }
}
Example #30
0
	void dfs_insert(vector<vector<string>> &res, deque<string> &strpath, unordered_map<string, vector<string>> &path, string & key)
	{
		vector<string> before = path[key];
		int len = before.size();
		for(int i=0; i<len; i++)
		{
			string now_key = before[i];
			if(now_key.empty())
			{
				vector<string> temp(strpath.begin(), strpath.end());
				res.push_back(temp);
			}
			else
			{
				strpath.push_front(now_key);
				dfs_insert(res, strpath, path, now_key);
				strpath.pop_front();
			}
		}
	}