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

63ms

Posted by ACAccepted at 2018-08-26 11:12:46 on Problem 3903
#include <cstdio>
using namespace std;
int n,loca,t;
int a[100005],q[100005];

int Find(int l,int r,int x)
{
	if(x<q[l])return l;
	if(q[l]==x)return l;
	if(q[r]==x)return r;
	if(r-l==1 && q[l]<x && x<q[r])return r;
	int mid=(l+r)/2;
	if(q[mid]<x)return Find(mid+1,r,x);
	else return Find(l,mid,x);
}

int main()
{
	q[0]=-1000000;
	while(scanf("%d",&n)!=EOF && n)
	{
		t=0;
		for(int i=1;i<=n;i++)scanf("%d",&a[i]);
		for(int i=1;i<=n;i++)
		{
			if(a[i]>q[t])q[++t]=a[i];
			else 
			{
				loca=Find(1,t,a[i]);
				q[loca]=a[i];
			}
		}
		printf("%d\n",t);
	}
	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