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

哪位大牛帮忙看看 二分 why WA?

Posted by xiaoyufeng at 2009-03-15 14:38:36 on Problem 2533
#include<stdio.h>
int a[1010],b[1010];
int binary(int *s,int m,int n)
{
	int left,right,mid;
	left=1;
	right=m;
	while(left<right-1)
	{
		mid=(left+right)/2;
		if(s[mid]<=n)
			left=mid;
		else
			right = mid;
	}
	if(s[left]>n)
	    return left;
	return right;
}
int main()
{
	int i,j,k;
	int t;
	while(scanf("%d",&t)!=EOF)
	{	
		for(i=1;i<=t;i++)
			scanf("%d",&a[i]);
			b[1]=a[1];
			k=1;
			for(i=2;i<=t;i++)
			{
				if(a[i]>=b[k])
				{
				    k++;
					b[k]=a[i]; 
				}
				else
				{
					j=binary(b,k,a[i]);
		            b[j]=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