Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:我怀疑这道题目的数据有问题啊。我用了一个标准的二分查找,可也错了。In Reply To:我怀疑 Posted by:ZSUKINGDOM at 2005-05-18 15:40:57 我的程序如下: #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator