B. Best Permutation

文章目录

  • 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();}
}

1728 problem B相关推荐

  1. BZOJ 3224: Tyvj 1728 普通平衡树 treap

    3224: Tyvj 1728 普通平衡树 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...

  2. linux下yum错误:[Errno 14] problem making ssl connection Trying other mirror.

    所有的base 都要取消注释 mirrorlist 加上注释 另外所有的enable都要设为零 目录 今天是要yum命令安装EPEL仓库后 yum install epel-release 突然发现y ...

  3. A + B Problem

    1001: A + B Problem Description 计算 A + B. Input 多组测试数据,每组测试数据占一行,包括2个整数. Output 在一行中输出结果. Sample Inp ...

  4. Error:(49, 1) A problem occurred evaluating project ':guideview'. Could not read script 'https://r

    出现问题如下: Error:(49, 1) A problem occurred evaluating project ':guideview'. > Could not read script ...

  5. #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)

    题目链接:http://codeforces.com/contest/814/problem/B 题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 ...

  6. ADPRL - 近似动态规划和强化学习 - Note 3 - Stochastic Infinite Horizon Problem

    Stochastic Infinite Horizon Problem 3.Stochastic Infinite Horizon Problem 定义3.1 无限范围的马尔可夫决策过程 (Marko ...

  7. ADPRL - 近似动态规划和强化学习 - Note 2 - Stochastic Finite Horizon Problem

    2. Stochastic Finite Horizon Problem 在这一节中主要介绍了随机DP算法来解决不确定性下的有限地范围问题,如Denition 1.4所述,它被表述为一个组合优化问题. ...

  8. There was a problem confirming the ssl certificate ……

    在安装一个Python库onetimepass时发生下面的问题: pip install onetimepass Could not fetch URL https://pypi.python.org ...

  9. HDU 1757 A Simple Math Problem

    Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x & ...

最新文章

  1. Numpy基础学习与总结
  2. CMM/CMMI的20年和敏捷十年
  3. 【Apache POI】Java Web根据模板导出word文件
  4. php获取dropzone上传的文件,php - 如何上传文件,使用php中的dropzone将文件详细信息保存到mysql数据库 - SO中文参考 - www.soinside.com...
  5. Java 获取目录的大小
  6. 如何提取明细表头_如何在实际操作中应用偏移修剪?
  7. java怎么使用wcf_如何使用WCF服务
  8. 突破大文件上传 和内网ip的端口转发
  9. numpy——flat与flatten
  10. html5移动端转盘,基于zepto适合移动端的幸运大转盘插件
  11. linux usb有线网卡驱动_Linux系统下安装USB无线网卡驱动方法
  12. MSCL超级工具类(C#),开发人员必备,开发利器
  13. 软件测试肖sir__006xmind思维导图实战__微信发红包
  14. 【java校招你不知道的那些事儿】java校招有没有考点大纲?不能拿面试补缺
  15. Houdini粒子随机大小每帧变化问题
  16. 在matlab中生成m序列
  17. 初识大数据(二)医疗大数据
  18. 尝试用HSDB分析JVM运行时内存理解Java多态实现机制
  19. SQL insert插入中存在属性值为空
  20. AttributeError: ‘Dataset‘ object has no attribute ‘value‘--H5py的历史遗留问题

热门文章

  1. 使用burp-suite对投票系统进行攻击
  2. css清除浮动的几种方式
  3. 如何解决Windows 无法完成格式化SD卡问题?
  4. TCP UDP IP
  5. Caffe2 Synchronous SGD
  6. web前段网图分类规划
  7. java项目——防止羊毛党“薅羊毛”
  8. JLink的RTT调试
  9. gsoap应用---利用gsoap工具生成代码
  10. 一文告诉你数据安全平台(DSP)能做什么