#include<iostream> #include<algorithm> usingnamespacestd ; int data[1001] ; boolcmp(int a ,int b) { return a< b ; } typedefstructNode { int s ; int e ; }Nodes ; Nodes Queen[10001]; int cur = 0 ; int total = 0 ; voidprint(int s , int e ) { if(s>=e) return ;
int sum = e -s; int mid ; int count = 1 ; while(sum >= count ) { sum -= count ; count *=2 ; } if(sum <= count/2) mid = (e-s-1-sum)/2 + sum ; else mid = (e-s-1-sum)/2 + count/2 ; if(!cur) cout << data[s+mid]; elsecout <<" "<<data[s+mid] ; Queen[total].s =s ; Queen[total++].e = s+mid ; Queen[total].s =s+mid+1 ; Queen[total++].e = e ; //print(s,s+mid-1); //print(s+mid+1,e) ; } intmain(){ int N ; cin >> N ; for(int i = 0 ; i< N ;i++) cin >> data[i] ; sort(data , data+N ,cmp); Queen[total].s = 0 ; Queen[total++].e = N ; while(cur < total ) { print( Queen[cur].s , Queen[cur].e) ; cur++ ; } }