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

我觉得是你的程序有问题,我这样做是超时,汇编写的partition和nth_element也超

Posted by frkstyc at 2005-05-18 15:44:45 on Problem 2104
In Reply To:Re:我怀疑这道题目的数据有问题啊。我用了一个标准的二分查找,可也错了。 Posted by:ZSUKINGDOM at 2005-05-18 15:43:23
> 我的程序如下:
> #include <stdio.h>
> const long N=110000;
> long a[N],b[N];
> long partition(long p,long r)
> {
> 	long temp,t;
> 	temp=b[(p+r)/2];
> 	while (p<r)
> 	{
> 		while (b[r]>temp) r--;
> 		while (b[p]<temp) p++;
> 		if (p<r)
> 		{
> 			if (b[p]!=b[r]) {t=b[r];b[r]=b[p];b[p]=t;}
> 			r--;p++;
> 		}
> 	}
> 	return r;
> }
> long find(long p,long r,long k)
> {
> 	long i,q;
> 	if (p==r) return b[p];
> 	q=partition(p,r);
> 	i=q-p+1;
> 	if (i>=k) return find(p,q,k);
> 	else return find(q+1,r,k-i);
> }
> int main()
> {
> 	long m,n,i,j,k,t,ii;
>  	scanf("%ld%ld",&n,&m);
> 	for (i=0;i<n;i++)
> 		scanf("%ld",&a[i]);
> 	while (m--)
> 	{
> 		scanf("%ld%ld%ld",&i,&j,&k);
> 		for (ii=0;i<=j;i++,ii++) b[ii]=a[i-1];
> 		t=find(0,ii-1,k);
> 		printf("%ld\n",t);
> 	}
> 	return 1;
> }

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