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 |
第一次 一次就ac 纪念一下!!! 哈哈~~~ 代码贴上第一次 一次就ac 纪念一下!!! 哈哈~~~ 代码贴上 #include<stdio.h> #define N 100000 typedef int type; int partition(type *tt,int low,int high); void Qsort(type *tt,int low,int high); int main() { int n,i,tt[N]; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&tt[i]); Qsort(tt,0,n-1); printf("%d\n",tt[(n-1)/2]); return 0; } int partition(type *tt,int low,int high) { type pivotkey; pivotkey=tt[low]; while(low<high) { while(low<high && tt[high]>=pivotkey) high--; tt[low]=tt[high]; while(low<high && tt[low]<=pivotkey) low++; tt[high]=tt[low]; } tt[low]=pivotkey; return low; } void Qsort(type *tt,int low,int high) { int pivot; if(low<high) { pivot=partition(tt,low,high); Qsort(tt,low,pivot-1); Qsort(tt,pivot+1,high); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator