| ||||||||||
| 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 | |||||||||
做了快一个小时 大家看看吧In Reply To:兄弟们帮帮忙 到底哪里出错了。。。。。。(代码见内) Posted by:wahahaha at 2005-10-02 20:52:34 > #include <stdio.h>
> #define N 2500
> long int a[N];
> long int findmin(long l,long r)
> {
> long int result=l,i,tmp;
> for(i=l+1;i<=r;i++)
> if(a[result]>a[i])
> result=i;
> tmp=a[l];
> a[l]=a[result];
> a[result]=tmp;
> return a[l];
>
>
> }
> long int findmax(long l,long r)
> {
> long int result=l,i,tmp;
> for(i=l+1;i<=r;i++)
> if(a[result]<a[i])
> result=i;
> tmp=a[l];
> a[l]=a[result];
> a[result]=tmp;
> return a[l];
> }
> long int find(long l,long r,long pos)
> {
> long i=l-1,j=r+1,tmp,tmp2;
>
> if(pos==l)return findmin(l,r);
> if(pos==r)return findmax(l,r);
> tmp=a[l];
> while(i<j)
> {
> while(a[++i]<tmp);
> while(a[--j]>tmp);
> if(i<j)
> {
> tmp2=a[i];
> a[i]=a[j];
> a[j]=tmp2;
> }
> }
> if(j>=pos)return find(l,j,pos);
> else return find(j+1,r,pos);
> }
> int main()
> {
> long int n,mid,i;
> double result;
> scanf("%ld",&n);
> for(i=1;i<=n;i++)
> scanf("%ld",&a[i]);
> mid=(n+1)/2;
> if(n%2==1)
> printf("%ld\n",find(1,n,mid));
> else
> {
> result=find(1,n,mid)+findmin(mid+1,n);
> result/=2.0;
> 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