Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用了个堆栈总是wa,谁知道为什么啊

Posted by dakecaoxin at 2009-09-13 14:52:03 on Problem 2533
就是按照顺序入栈,然后弹出j后,再把j之后的按顺序入栈,最后记录最长的栈。
希望牛人指点算法的问题,谢谢!!!

#include<iostream>
using namespace std;
#define MaxStackSize 1050
class Stack
{
private:
	int stacklist[MaxStackSize];
	int top;
public:
	 Stack(void);
	 void Push(int a);
	 int Pop(void);
	 int Peek(void);
	 int count(void);

};
Stack::Stack(){top=-1;}
void Stack::Push(int a)
{
	if(top==MaxStackSize-1)
	{
		exit(1);
	}
	top++;
	stacklist[top]=a;
}
int Stack::Pop()
{
	int temp;
	if(top==-1)
	{
	}
	
	temp=stacklist[top];
	top--;
	return temp;
}
int Stack::Peek()
{
	int temp;
	if(top==-1)
	{
	}
	
	temp=stacklist[top];
	return temp;
}
int Stack::count()
{
	int temp = top +1;
	return temp;
}

int main()
{
	int a[1050];
	int n;
	int order=0;
	int max=1;
	int j;
	Stack sign;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}

	sign.Push(0);
	sign.Push(0);
	while(1)
	{
		max=sign.Pop();
		for(j=max+1;j<n;j++)
			{
				if(a[j]>a[sign.Peek()])
				{
				
					sign.Push(j);
				}
				
			}
			if(order<sign.count()) order=sign.count();
			if(sign.count()==0) break;

	}
cout <<order<<endl;
	
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator