URAL真是没水题 以为简单的排序就好了 ME 内存限制很紧 堆排序 或者 STL
用堆排序做的 正好复习一下 都忘了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 using namespace std; 7 #define N 1250010 8 int a[N]; 9 void adjust(int i,int n) 10 { 11 int j; 12 a[0] = a[i]; 13 j = 2*i; 14 while(j<=n) 15 { 16 if(j<n&&a[j+1]>a[j]) 17 j++; 18 if(a[0]<a[j]) 19 { 20 a[i] = a[j]; 21 i = j; 22 j = 2*i; 23 } 24 else 25 break; 26 } 27 a[i] = a[0]; 28 } 29 int main() 30 { 31 int i,j,n,t,x; 32 scanf("%d",&n); 33 int k = n/2+1; 34 for(i = 1; i <= k ; i++) 35 scanf("%d",&a[i]); 36 if(n==2) 37 { 38 printf("%.1lf ",(a[2]/2.0+a[1]/2.0)); 39 return 0; 40 } 41 for(i = k/2 ; i>= 1 ; i--) 42 adjust(i,k); 43 for(i = k+1 ; i <= n ; i++) 44 { 45 scanf("%d",&x); 46 if(x<a[1]) 47 { 48 a[1] = x; 49 adjust(1,k); 50 } 51 } 52 for(i = k ; i >1 ; i--) 53 { 54 t = a[1]; 55 a[1] = a[i]; 56 a[i] = t; 57 adjust(1,i-1); 58 } 59 if(n%2!=0) 60 printf("%.1lf ",1.0*a[k]); 61 else 62 printf("%.1lf ",a[k-1]/2.0+a[k]/2.0); 63 return 0; 64 }