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. 使用Relay部署编译ONNX模型
  2. React native 浏览器调试
  3. Java:main()函数调用类中方法的限制
  4. 怎么打包图片_超简单的免费批量图片压缩技巧,只需3步
  5. 操作系统(1) 发展历史
  6. Ubuntu下安装支付宝安全控件
  7. Tomcat端口占用的处理方式
  8. 用python爬取杭电oj的数据
  9. VS提示SurfFeatureDetector不是cv的成员函数 .
  10. 方差分析软件_重复测量方差分析的操作教程及结果解读
  11. 兄弟连php课程,LAMP兄弟连PHP课程学习笔记 第一天 PHP基本语法
  12. python 图片合并pdf_利用python将多张图片合并为pdf文档
  13. 北京东方时尚学车日志
  14. 神舟 桌面显示计算机,神舟笔记本双显卡怎么切换不盯道你的笔记本型号
  15. MYSQLg高级------聚簇索引和非聚簇索引
  16. android targetsdkversion 版本 调低,targetSdkVersion 更改的问题
  17. 《基于移动互联的智慧健康社区系统的研发》 CSCD
  18. 【再学Tensorflow2】TensorFlow2的建模流程:Titanic生存预测
  19. IE 11 浏览器兼容性视图设置
  20. 思维模型 塔西陀陷阱

热门文章

  1. pyqt创建窗口没有句柄_史上最强之《Pyqt》写游戏
  2. php面试自我介绍结束语,面试自我介绍 结尾 社团招新面试自我介绍
  3. Contiki内核原理
  4. 【openjudge】金银岛
  5. Jodd HTTP的使用
  6. 源代码转换:Tangible Software Solutions v22.10.20
  7. Linux 处理目标文件的工具(指令)
  8. 【学习求职必备】认真认识一下世界末日那年成立的“华为诺亚方舟实验室”...
  9. No module named 'urllib3'
  10. 怎么用计算机算自己的月经周期,【月经周期表】月经周期表计算器_女人月经周期表 - 妈妈网百科...