Exemple #1
0
 int min() {
     return minimums.top();
 }
int next(){
	TreeNode* cur = stk.top();
	stk.pop();
	push(cur->right);
	return cur->val;	
}
Exemple #3
0
// get one relation from stack
relation Token::get_relation() {
          relation r = relation_set.top();
          relation_set.pop();
          return r;
}
Exemple #4
0
void rightMultiply(const mat4 &M, stack<mat4> &transfstack)
{
    mat4 &T = transfstack.top();
    T = T * M;
}
Exemple #5
0
 int top() {
     return s.top();
 }
Exemple #6
0
 int min() {
     return minStack.top();
 }
Exemple #7
0
inline void bk(stack<int>& from, stack<int>& to) {
    from.push(to.top());
    to.pop();
}
Exemple #8
0
 int getMin() {
     return stk_min.top();
 }
void XapianEngine::stackQuery(const QueryProperties &queryProps,
	stack<Xapian::Query> &queryStack, const string &stemLanguage, bool followOperators)
{
	Xapian::Query::op queryOp = Xapian::Query::OP_OR;
	string term;

	// Get the terms to AND together
	if (queryProps.getAndWords().empty() == false)
	{
		vector<string> andTerms;

		if (extractWords(queryProps.getAndWords(), stemLanguage, andTerms) == true)
		{
#ifdef DEBUG
			cout << "XapianEngine::stackQuery: OP_AND "  << andTerms.size() << endl;
#endif
			if (followOperators == true)
			{
				queryOp = Xapian::Query::OP_AND;
			}
			queryStack.push(Xapian::Query(queryOp, andTerms.begin(), andTerms.end()));
		}
	}

	// Get the terms of the phrase
	if (queryProps.getPhrase().empty() == false)
	{
		vector<string> phraseTerms;

		if (extractWords(queryProps.getPhrase(), stemLanguage, phraseTerms) == true)
		{
#ifdef DEBUG
			cout << "XapianEngine::stackQuery: OP_PHRASE "  << phraseTerms.size() << endl;
#endif
			if (followOperators == true)
			{
				queryOp = Xapian::Query::OP_PHRASE;
			}
			queryStack.push(Xapian::Query(queryOp, phraseTerms.begin(), phraseTerms.end()));
		}
	}

	// Get the terms to OR together
	if (queryProps.getAnyWords().empty() == false)
	{
		vector<string> orTerms;

		if (extractWords(queryProps.getAnyWords(), stemLanguage, orTerms) == true)
		{
#ifdef DEBUG
			cout << "XapianEngine::stackQuery: OP_OR "  << orTerms.size() << endl;
#endif
			if (followOperators == true)
			{
				queryOp = Xapian::Query::OP_OR;
			}
			queryStack.push(Xapian::Query(queryOp, orTerms.begin(), orTerms.end()));
		}
	}

	// Get the terms to NOT together
	if (queryProps.getNotWords().empty() == false)
	{
		vector<string> notTerms;

		if (extractWords(queryProps.getNotWords(), stemLanguage, notTerms) == true)
		{
#ifdef DEBUG
			cout << "XapianEngine::stackQuery: OP_AND_NOT "  << notTerms.size() << endl;
#endif
			// We need something to AND_NOT these terms against
			// Not following the operator would make us return documents
			// that have terms the user isn't interested in
			Xapian::Query notQuery(Xapian::Query::OP_AND, notTerms.begin(), notTerms.end());
			if (queryStack.empty() == false)
			{
				Xapian::Query topQuery = queryStack.top();
				queryStack.pop();

				queryStack.push(Xapian::Query(Xapian::Query::OP_AND_NOT, topQuery, notQuery));
			}
		}
	}

	// Get the host name filter
	if (queryProps.getHostFilter().empty() == false)
	{
		vector<string> hostTerms;

		term = "H";
		term += StringManip::toLowerCase(queryProps.getHostFilter());
		hostTerms.push_back(term);
		if (followOperators == true)
		{
			queryOp = Xapian::Query::OP_AND;
		}
		queryStack.push(Xapian::Query(queryOp, hostTerms.begin(), hostTerms.end()));
	}

	// Get the file name filter
	if (queryProps.getFileFilter().empty() == false)
	{
		vector<string> fileTerms;

		term = "P";
		term += StringManip::toLowerCase(queryProps.getFileFilter());
		fileTerms.push_back(term);
		if (followOperators == true)
		{
			queryOp = Xapian::Query::OP_AND;
		}
		queryStack.push(Xapian::Query(queryOp, fileTerms.begin(), fileTerms.end()));
	}

	// Get the label name filter
	if (queryProps.getLabelFilter().empty() == false)
	{
		vector<string> labelTerms;

		term = "XLABEL:";
		term += queryProps.getLabelFilter();
		labelTerms.push_back(term);
		if (followOperators == true)
		{
			queryOp = Xapian::Query::OP_AND;
		}
		queryStack.push(Xapian::Query(queryOp, labelTerms.begin(), labelTerms.end()));
	}

	// Get the language filter
	string language = queryProps.getLanguage();
	if (language.empty() == false)
	{
		vector<string> languageTerms;

		term = "L";
		term += Languages::toCode(Languages::toEnglish(language));
#ifdef DEBUG
		cout << "XapianEngine::stackQuery: filter "  << term << endl;
#endif
		languageTerms.push_back(term);
		if (followOperators == true)
		{
			queryOp = Xapian::Query::OP_AND;
		}
		queryStack.push(Xapian::Query(queryOp, languageTerms.begin(), languageTerms.end()));
	}
}
 /** @return the next smallest number */
 int next() {
     TreeNode *cur = myStack.top();
     myStack.pop();
     pushAll(cur->right);
     return cur->val;
 }
void getAllStack(){
	while( st.size() != 0 ){
		ans.push_back(st.top());
		st.pop();
	}
}
void rightmultiply(const mat4 & M, stack<mat4> &transfstack) {
    mat4 &T = transfstack.top() ;
    // Right multiply M, but do this left to account for row/column major
    T = T*M  ;
}
// The function below applies the appropriate transform to a 4-vector
void matransform(stack<mat4> &transfstack, GLfloat * values) {
    mat4 transform = transfstack.top() ;
    vec4 valvec = vec4(values[0],values[1],values[2],values[3]) ;
    vec4 newval = valvec * transform ;
    for (int i = 0 ; i < 4 ; i++) values[i] = newval[i] ;
}
 // Get the front element.
 int peek(void) {
 	if (stk1.empty())
 		return stk2.top();
 	else
 		return stk1.top();
 }
Exemple #15
0
//devuelve el primer elemento de "mi_pila"
string getTope(stack<string> mi_pila)
{
    return mi_pila.top(); // con el top() nos permite devolver el elemento dentro de la pila
}
Exemple #16
0
long long find_rectangle(long long A[],long long size)
{
	long long i , index;

	// Finding value of R[i]
	MyStack_R.push(0);
	for(i=1;i<size;i++)
	{

		if(A[i]>=A[MyStack_R.top()])
		{
			MyStack_R.push(i);
		}
		else
		{
			while(!MyStack_R.empty())
			{	
				if((A[i]<A[MyStack_R.top()]))
				{
					index=MyStack_R.top();
					MyStack_R.pop();
					R[index]=i-1;
				}
				else 
					break;
			}
			MyStack_R.push(i);

		}
	}
	while(!MyStack_R.empty())
	{
		index=MyStack_R.top();
		MyStack_R.pop();
		R[index]=i-1;
	}
	// Finding value of L[i]
	MyStack_L.push(size-1);
	for(i=size-2;i>=0;i--)
	{
		if(A[i]>=A[MyStack_L.top()])
			MyStack_L.push(i);
		else
		{       
			while(!MyStack_L.empty())
			{
				if(A[i]<A[MyStack_L.top()])
				{
					index=MyStack_L.top();
					MyStack_L.pop();
					L[index]=i+1;
				}
				else
					break;
			}
			MyStack_L.push(i);
		}
	}
	while(!MyStack_L.empty())
	{
	index=MyStack_L.top();
	MyStack_L.pop();
	L[index]=0;
	}

	long long CheckI[MAX];
	long long maxi=0;
	for(i=0;i<size;i++)
	{
		CheckI[i]=A[i]*(-L[i]+R[i]+1);
		if(CheckI[i]>maxi)
			maxi=CheckI[i];
	}
	return maxi;

}
Exemple #17
0
 double getResult()
 {
   if(stk.size() != 1)
     throw "Improperly written expression";
   return stk.top();
 }
Exemple #18
0
 void push(int x) {
     if (mstk.empty() || x <= mstk.top())
         mstk.push(x);
     stk.push(x);
 }
Exemple #19
0
 void push(int number) {
     dataStack.push(number);
     if(minStack.empty() || number <= minStack.top()){
         minStack.push(number);
     }
 }
Exemple #20
0
 void pop() {
     if (stk.top() == mstk.top())
         mstk.pop();
     stk.pop();
 }
Exemple #21
0
inline int vpop(stack<int> &s)
{
	int x = s.top();
	s.pop();
	return x;
}
Exemple #22
0
 int top() {
     return stk.top();
 }
Exemple #23
0
 void push(int data) {
     s.push(data);
     if (s_min.empty() || data <= s_min.top()) {
         s_min.push(data);
     }
 }
Exemple #24
0
 int getMin() {
     return mstk.top();
 }
Exemple #25
0
 int min() {
     return s_min.top();
 }
Exemple #26
0
state pda_stack(char x, state currstat){
    if (x=='$'&&currstat==Q2){
        cout << "Popped: (epsilon) | ";
        mystack.push(x);        // pushing the $ on the stack
        cout << "Pushed: " << mystack.top() << " | ";
        return currstat;
    }
    else if (x=='('&&currstat==Q4){
        cout << "Popped: (epsilon) | ";
        mystack.push(x);  // pushing the open parenthesis
        cout << "Pushed: " << mystack.top() << " | ";
        return currstat;
    }
    else if (x==')'&&currstat==Q5){     // if read close parenthesis then popped the open parenthesis on the stack
        cout << "Popped: " << mystack.top() << " | "; //print what is in the top of the stack
        mystack.pop();  // and pop it
        cout << "Pushed: (epsilon) | ";
        return currstat;
    }
    else if ((x=='+'||x=='-'||x=='*'||x=='/')&&currstat==Q6){
        cout << "Popped: (epsilon) | ";
        mystack.push(x);  // pushing the operator to avoid '+-' (two operator together)
        cout << "Pushed: " << mystack.top() << " | ";
        return currstat;
    }
    else if ((x!='+'&&x!='-'&&x!='*'&&x!='/'&&x!='('&&x!=')')&&currstat==Q9&&(mystack.size()>=1)){ // if read a string from Q6 must popped the operator
        cout << "Popped: " << mystack.top() <<" | ";
        mystack.pop();
        cout << "Pushed: (epsilon) | ";
        return currstat;
    }
    else if (x==')'&&currstat==Q7&&(mystack.size()>=1)&&mystack.top()=='('){ // if read close parenthesis then popped the open parenthesis on the stack
        cout << "Popped: " << mystack.top() << " | ";
        mystack.pop();
        cout << "Pushed: (epsilon) | ";
        return currstat;
    }
    else if (x==')'&&currstat==Q9&&(mystack.size()>=1)){ // if read close parenthesis then popped the open parenthesis on the stack
        cout << "Popped: " << mystack.top() << " | ";
        mystack.pop();
        cout << "Pushed: (epsilon) | ";
        return currstat;
    }
    else if (x=='$'&&currstat==Q8&&(mystack.size()>=1)&&mystack.top()=='$'){  // in order to accept the string it must end with the dollar sign
        cout << "Popped: " << mystack.top() << " | ";
        mystack.pop();
        cout << "Pushed: (epsilon) | ";
        return currstat;
    }
    else if ((x!='+'&&x!='-'&&x!='*'&&x!='/'&&x!='('&&x!=')'&&x!='$')){  //everthing else is episolon
        cout << "Popped: (epsilon) | ";
        cout << "Pushed: (epsilon) | ";
        return currstat;
    }
    else if (x=='('&&currstat==Q10){   // popped the operator if read the next string with open parenthesis. e.i. $a+(a+a)$
        cout << "Popped: " << mystack.top() << " | ";
        mystack.pop();
        cout << "Pushed: " << x << " | ";
        mystack.push(x);
        return currstat;
    }
    else
        return TEMP_ERROR;      //return error if the stack is empty when you trying to popped something. e.i. $(a+a))$
}
 void transfer_stack_data() {
     while (!s1.empty()) {
         s2.push(s1.top());
         s1.pop();
     }
 }
int main(){
	scanf("%d", &T);
	for (t = 1; t <= T; t++){
			
		scanf("%d %d %d %d", &R, &C, &m, &n);
		scanf("%d", &W);

		for (i = 0; i < R; i++)
			for (j = 0; j < C; j++)
				grid[i][j] = 0;

		for (i = 0; i < W; i++){
			scanf("%d %d", &x, &y);
			grid[x][y] = -1;
		}

		if (m < n) swap(m, n);
		
		int ansE = 0; int ansO = 0;
		s.push(mp(0, 0));
		while (!s.empty()){
			int count = 0;
					
			pii p = s.top(); s.pop();
			if(grid[p.fst][p.snd] > 0)
				continue;
			grid[p.fst][p.snd] = 1;
			
			if(n == 0){
				if(p.fst + m < R && grid[p.fst+m][p.snd] > -1){
					count++;
					s.push(mp(p.fst+m, p.snd));
				}
				if(p.fst - m >= 0 && grid[p.fst-m][p.snd] > -1){
					count++;
					s.push(mp(p.fst-m, p.snd));
				}
				if(p.snd + m < C && grid[p.fst][p.snd+m] > -1){
					count++;
					s.push(mp(p.fst, p.snd+m));
				}
				if(p.snd - m >= 0 && grid[p.fst][p.snd-m] > -1){
					count++;
					s.push(mp(p.fst, p.snd-m));
				}
			} else {
				if(p.fst + n < R && p.snd + m < C && grid[p.fst+n][p.snd+m] > -1){
					count++;
					s.push(mp(p.fst+n, p.snd+m));
				}
				if(p.fst + n < R && p.snd - m >= 0 && grid[p.fst+n][p.snd-m] > -1){
					count++;
					s.push(mp(p.fst+n, p.snd-m));
				}if(p.fst - n >= 0 && p.snd + m < C && grid[p.fst-n][p.snd+m] > -1){
					count++;
					s.push(mp(p.fst-n, p.snd+m));
				}if(p.fst - n >= 0 && p.snd - m >= 0 && grid[p.fst-n][p.snd-m] > -1){
					count++;
					s.push(mp(p.fst-n, p.snd-m));
				}
				if(n !=m) {
					swap(n, m);
				if(p.fst + n < R && p.snd + m < C && grid[p.fst+n][p.snd+m] > -1){
					count++;
					s.push(mp(p.fst+n, p.snd+m));
				}
				if(p.fst + n < R && p.snd - m >= 0 && grid[p.fst+n][p.snd-m] > -1){
					count++;
					s.push(mp(p.fst+n, p.snd-m));
				}if(p.fst - n >= 0 && p.snd + m < C && grid[p.fst-n][p.snd+m] > -1){
					count++;
					s.push(mp(p.fst-n, p.snd+m));
				}if(p.fst - n >= 0 && p.snd - m >= 0 && grid[p.fst-n][p.snd-m] > -1){
					count++;
					s.push(mp(p.fst-n, p.snd-m));
				}
				}
			}
			if (count%2 == 1)
				ansO++;
			else 
				ansE++;
		}
		printf("Case %d: %d %d\n", t, ansE, ansO);
	}
}
Exemple #29
0
int minStack::min()
{
	return minS.top();
}
Exemple #30
0
 int max() {
     return maximums.top();
 }