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

help!!!!!!!!!!!!!!!!Give me you hand......thanks,Why WA??????

Posted by 418467677 at 2008-08-31 22:52:25 on Problem 2533
#include <iostream>
using namespace std;
int a[5005];
int b[5005];
int bi(int i,int k)//二分查找
{
	int h,j;
	if(a[i]<b[1])return 1;
	for(h=1,j=k;h!=j-1;)
	{
		if(b[k=(h+j)/2]<=a[i])h=k;
		else
			j=k;
	}
	return j;
}
int main()
{
	int n;
	int i,k;
	while(scanf("%d",&n)!=EOF){	
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		b[1]=a[0];
		for(i=1,k=1;i<n;i++)
		{
			if(a[i]>=b[k])
				b[++k]=a[i];
			else
				b[bi(i,k)]=a[i];
		}
		printf("%d\n",k);
	}
	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