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 |
换了QSORT 又出了问题 郁闷!~In Reply To:做了快一个小时 大家看看吧 Posted by:wahahaha at 2005-10-02 21:00:53 #include <stdio.h> #include <math.h> #define N 25000 long a[N]; long p(long l,long r) { long i=l-1,j=r+1,tmp=a[l],tmp2; while(i<j) { while(a[++i]<tmp); while(a[--j]>tmp); if(i<j) { tmp2=a[i]; a[i]=a[j]; a[j]=tmp2; } } return j; } void qsort(long l,long r) { long mid; if(l<r) { mid=p(l,r); qsort(l,mid); qsort(mid+1,r); } } int main() { long n,i; double result; scanf("%ld",&n); for(i=1;i<=n;i++) scanf("%ld",&a[i]); qsort(1,n); if(n%2==1) printf("%ld\n",a[(n+1)/2]); else { result=a[n/2]+a[(n+2)/2]; result/=2.0; if(fmod(result,1.0)==0) printf("%.0lf\n",result) ; else printf("%.1lf\n",result) ; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator