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 252840273 at 2016-03-12 15:54:31 on Problem 2533
#include <iostream>
#include <algorithm>
#include<queue>
#include<stack> 
#define max(a,b) a>b?a:b
using namespace std;
int ans=1;
int num;
int numall[10001];
void lcs(int a[],int n){
	stack<int>s;
	s.push(a[0]);
	int length=1;
	int last=a[0];
	for(int i=1;i<n;i++){
		if(a[i]>last){
			s.push(a[i]);
			length++;
			last=a[i];			
		}
		else if(a[i]<last){
			ans=max(ans,length);
			while(a[i]<last&&!s.empty()){
				length--;
				s.pop();
				last=s.top();
			}
			s.push(a[i]);
			length++;
		}			
	}	
}
int main(){
	while(cin>>num){
		ans=1;
		int i=0;
		while(i<num)scanf("%d",&numall[i++]);
		lcs(numall,num);
		printf("%d\n",ans);
	}
}


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