1728 problem B

B. Best Permutation

题意

Let’s define the value of the permutation pp of nn integers 11, 22, …, nn (a permutation is an array where each element from 11 to nn occurs exactly once) as follows:

  • initially, an integer variable xx is equal to 00;
  • if x<p1x<p1, then add p1p1 to xx (set x=x+p1x=x+p1), otherwise assign 00 to xx;
  • if x<p2x<p2, then add p2p2 to xx (set x=x+p2x=x+p2), otherwise assign 00 to xx;
  • if x<pnx<pn, then add pnpn to xx (set x=x+pnx=x+pn), otherwise assign 00 to xx;
  • the value of the permutation is xx at the end of this process.

For example, for p=[4,5,1,2,3,6]p=[4,5,1,2,3,6], the value of xx changes as follows: 0,4,9,0,2,5,110,4,9,0,2,5,11, so the value of the permutation is 1111.

You are given an integer nn. Find a permutation pp of size nn with the maximum possible value among all permutations of size nn. If there are several such permutations, you can print any of them.

Input

The first line contains one integer tt (1≤t≤971≤t≤97) — the number of test cases.

The only line of each test case contains one integer nn (4≤n≤1004≤n≤100).

Output

For each test case, print nn integers — the permutation pp of size nn with the maximum possible value among all permutations of size nn.

题解

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
void solve()
{
    int n;
    cin>>n;
    if(n%2 ==  0)
    {
        for(int i = n - 2 ;i >= 1 ; i --)
        {
            cout<<i<<" ";
        }
        cout<<n - 1 <<" "<<n<<endl;
        return;
    } else{
        cout<<1<<" ";
        for (int i = n - 2; i >=2 ; i -- ) {
            cout<<i<<" ";
        }
        cout<<n - 1 <<" "<<n<<endl;
        return;
    }

}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值