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

Re:既然水。。。比比谁的长。。。

Posted by S070703520 at 2009-07-26 13:42:39 on Problem 2533
In Reply To:既然水。。。比比谁的短。。。 Posted by:niuzheng168 at 2009-07-21 11:37:14
#include<stdio.h>

class Qnum
{
public:
	int m;
	int i;
	Qnum operator = (Qnum &x)
	{
		m=x.m;
		i=x.i;
		return *this;
	}
	bool operator > (Qnum &x)
	{
		return(m>x.m);
	}
	bool operator < (Qnum &x)
	{
		return(m<x.m);
	}
};

class Num
{
public:
	int mm;
	int c;
};

void swap(Qnum &a,Qnum &b)
{
	Qnum temp;
	temp=a;
	a=b;
	b=temp;
}

int partition(Qnum a[],int p,int r)
{   //划分算法
	int i=p,j=r+1;Qnum x=a[p];
	//将>=x的元素交换到左边区域
	//将<=x的元素交换到右边区域
	while(true)
	{
		while(a[++i]>x&&i<r);
		while(a[--j]<x);
		if(i>=j)break;
		swap(a[i],a[j]);
	}
	swap(a[j],a[p]);
	return j;
}

void quick_sort(Qnum a[],int p,int r)
{   //随机化的快速排序算法
	if(p<r)
	{
		int q=partition(a,p,r);
		quick_sort(a,p,q-1);//对左半段排序
		quick_sort(a,q+1,r);//对右半段排序
	}
}

int main()
{
	int i,j,n,max=0,tmp,tmax,flag;
	Qnum qnum[1003];
	Num num[1003];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i].mm);
		qnum[i].m=num[i].mm;
		qnum[i].i=i;
	}
	quick_sort(qnum,0,n-1);
	for(i=0;i<n;i++)
	{
		tmax=flag=0;
		for(j=qnum[i].i+1;j<n;j++)
		{
			if(num[qnum[i].i].mm<num[j].mm)
			{
				flag=1;
				tmp=num[j].c+1;
				tmax=tmax>tmp?tmax:tmp;
			}
		}
		if(flag)
			num[qnum[i].i].c=tmax;
		else
		{
			num[qnum[i].i].c=tmax=1;
		}
		max=max>tmax?max:tmax;
	}
	printf("%d\n",max);
	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