| ||||||||||
| 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 | |||||||||
谁帮忙看一下程序?我用的是快速排序,超时了……先谢谢了!#include<stdio.h>
int partition(long int r[],int low,int high)
{
int pivotkey;
r[0]=r[low];
pivotkey=r[low];
while(low<high)
{
while((low<high)&&(r[high]>pivotkey)){--high;}
r[low]=r[high];
while((low<high)&&(r[low]<pivotkey)){++low;}
r[high]=r[low];
}
r[low]=r[0];
return low;
}
void QSort(long int r[],int low,int high)
{
int pivotloc;
if(low<high)
{
pivotloc=partition(r,low,high);
QSort(r,low,pivotloc-1);
QSort(r,pivotloc+1,high);
}
}
void QuickSort(long int r[],int n)
{
QSort(r,1,n);
}
int main()
{
int n;
int i;
long int a[10001];
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
QuickSort(a,n);
printf("%ld",a[(n+1)/2]);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator