|
|
back to boardWA6 this is my solutioon please help me! #include <iostream> #include <stdio.h> using namespace std; long a[50001], sum=0; void merge(long,long,long); void merge_sort(long low,long high) { long mid; if(low<high) { mid=(low+high)/2; merge_sort(low,mid); merge_sort(mid+1,high); merge(low,mid,high); } } void merge(long low,long mid,long high) { long h,i,j,b[50001],k; h=low; i=low; j=mid+1; while((h<=mid)&&(j<=high)) { if(a[h]<=a[j]) { b[i]=a[h]; h++; } else { b[i]=a[j]; sum+=mid-h+1; j++; } i++; } if(h>mid) { for(k=j;k<=high;k++) { b[i]=a[k]; i++; } } else { for(k=h;k<=mid;k++) { b[i]=a[k]; i++; } } for(k=low;k<=high;k++) a[k]=b[k]; } int main(){
long num,i,a[50001];; cin>>num; for(i=1;i<=num;i++) { cin>>a[i] ; }if(num==1)cout<<a[1]; else{ merge_sort(1,num); cout<<a[num/2]; }return 0;} |
|
|