1.比赛时一开始想到递归二分,但是实际上没办法这样写,要分好多种情况。但是我只分析了样例以及7,8,9的情况,但是到了10又不行了,tcl
2.实际上正解就是使用优先队列维护每段区间的最优性,每次二分后子区间入队,很轻松就求解了,但是我没有想出来,需要反思…
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;
struct node{
int l,r,len;
bool operator < (const node& p) const {
if(len==p.len) return l>=p.l;
return len<p.len;
}
};
priority_queue<node> p;
int a[maxn];
int t,n;
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
cin>>n;
//while(!p.empty()) p.pop();
p.push(node{1,n,n});
int cnt=0;
while(!p.empty()){
node u=p.top(); p.pop();
int mid=(u.l+u.r)/2;
a[mid]=++cnt;
//cout<<u.l<<" "<<u.r<<endl;
//cout<<cnt<<endl;
if(u.l<=mid-1) p.push(node{u.l,mid-1,mid-u.l});
if(mid+1<=u.r) p.push(node{mid+1,u.r,u.r-mid});
}
for(int i=1;i<=n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
}
return 0;
}