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 zhb_msqx at 2007-08-31 09:40:45 on Problem 3298
#include <iostream>
#include <fstream>
using namespace std;

int n;
int a[30001];
int t[30001][2];
void main(){
	ifstream cin("data.txt");
	int testcase,i;
	cin>>testcase;
	while(testcase--){
		cin>>n;
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		if(n==1){
			cout<<1<<endl;
		}else{
			t[n-1][0]=1;t[n-1][1]=1; //t[n-1][1]代表后面的数比前面的小,t[n-1][0]代表比前面的大,从后往前递归
			int max=0;
			for(i=n-2;i>=0;i--){
				if(a[i]<a[i+1]){
					t[i][1]=1;
					t[i][0]=1+t[i+1][1];
				}else if(a[i]>a[i+1]){
					t[i][0]=1;
					t[i][1]=t[i+1][0]+1;
				}else{
					t[i][0]=t[i][1]=1;
				}
				if(t[i][1]>max)max=t[i][1];
			}
			cout<<max<<endl;
		}
	}	

}

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