A. Average Height(找相邻的数除2产生整数更多的排列)(codeforces715)

简介: A. Average Height(找相邻的数除2产生整数更多的排列)(codeforces715)

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

Sayaka Saeki is a member of the student council, which has n other members (excluding Sayaka). The i-th member has a height of ai millimeters.


It’s the end of the school year and Sayaka wants to take a picture of all other members of the student council. Being the hard-working and perfectionist girl as she is, she wants to arrange all the members in a line such that the amount of photogenic consecutive pairs of members is as large as possible.


A pair of two consecutive members u and v on a line is considered photogenic if their average height is an integer, i.e. (au+av)/2 is an integer.


Help Sayaka arrange the other members to maximize the number of photogenic consecutive pairs.


Input

The first line contains a single integer t (1≤t≤500) — the number of test cases.


The first line of each test case contains a single integer n (2≤n≤2000) — the number of other council members.


The second line of each test case contains n integers a1, a2, …, an (1≤ai≤2⋅105) — the heights of each of the other members in millimeters.


It is guaranteed that the sum of n over all test cases does not exceed 2000.


Output

For each test case, output on one line n integers representing the heights of the other members in the order, which gives the largest number of photogenic consecutive pairs. If there are multiple such orders, output any of them.


Example


inputCopy

4

3

1 1 2

3

1 1 1

8

10 9 13 15 3 16 9 13

2

18 9


outputCopy

1 1 2

1 1 1

13 9 13 15 3 9 16 10

9 18


Note

In the first test case, there is one photogenic pair: (1,1) is photogenic, as (1+1)/2=1 is integer, while (1,2) isn’t, as (1+2)/2=1.5 isn’t integer.


题意就是产生相邻的数除2产生整数更多的排列打印出来,我们就可以想到先排偶数然后在排奇数就可以得到最优排列,


听懂了记得给个赞鼓励一下,码字不易,用爱发电。


上ac代码。

f58230e9f063709cf3167704f4efdf14.gif


有事你就q我;QQ2917366383


学习算法

 

#include<iostream>
using namespace std;
const int maxn=1e6+7;
#define  ll long long
ll a[maxn];
int main()
{
  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
      cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
      if(a[i]%2==1)
      cout<<a[i]<<' ';
    }
      for(int i=1;i<=n;i++)
    {
      if(a[i]%2==0)
      cout<<a[i]<<' ';
    }
  }
}
相关文章
element-plus:el-table自定义展开图标处于列的位置
element-plus:el-table自定义展开图标处于列的位置
1203 0
|
运维 架构师
架构师“三部曲”——阿里云 MVP 沈剑
沈剑,公众号“架构师之路”的作者,曾任百度高级工程师和58同城高级架构师、技术委员会主席、技术学院优秀讲师,现为到家集团技术委员会主席和技术VP,同时也是快狗打车(原58速运)的CTO。本文是沈剑老师在阿里云的直播中分享的一些自己关于架构师的看法和成为架构师的心路历程的第二部分。
3854 0
架构师“三部曲”——阿里云 MVP 沈剑
|
10月前
|
存储 编译器 数据安全/隐私保护
【C++面向对象——类与对象】CPU类(头歌实践教学平台习题)【合集】
声明一个CPU类,包含等级(rank)、频率(frequency)、电压(voltage)等属性,以及两个公有成员函数run、stop。根据提示,在右侧编辑器补充代码,平台会对你编写的代码进行测试。​ 相关知识 类的声明和使用。 类的声明和对象的声明。 构造函数和析构函数的执行。 一、类的声明和使用 1.类的声明基础 在C++中,类是创建对象的蓝图。类的声明定义了类的成员,包括数据成员(变量)和成员函数(方法)。一个简单的类声明示例如下: classMyClass{ public: int
387 13
|
9月前
|
机器学习/深度学习 编解码 计算机视觉
RT-DETR改进策略【注意力机制篇】| CVPR-2023 FSAS 基于频域的自注意力求解器 结合频域计算和卷积操作 降低噪声影响
RT-DETR改进策略【注意力机制篇】| CVPR-2023 FSAS 基于频域的自注意力求解器 结合频域计算和卷积操作 降低噪声影响
367 2
|
存储 小程序 API
深入调查研究Memos
【11月更文挑战第1天】
334 7
|
Linux Shell Go
Linux中文件操作基本指令大全
Linux中文件操作基本指令大全
|
自然语言处理 数据安全/隐私保护 UED
如何选择适合的域名:关键步骤与策略
在数字化时代,域名不仅是网站的身份标识,更是品牌在线形象的重要组成部分。本文将指导您如何选择一个恰当、易于记忆且富有意义的域名,从明确目标与定位、选择合适的域名类型与后缀、考虑长度与可读性、检查可用性与合法性、评估SEO价值、考虑未来扩展、购买与注册到监测与维护,全方位帮助您打造优质域名。
492 4
|
Ubuntu 物联网 Linux
AliOS Things、Ubuntu、Linux、MacOS、Window
AliOS Things、Ubuntu、Linux、MacOS 和 Windows 都是操作系统,用于控制计算机或其他设备的硬件和软件资源。它们有以下不同点和特点: -AliOS Thing
672 2
|
弹性计算 并行计算 Linux
【玩转AIGC系列】从0快速搭建个人版“对话大模型”
本教程介绍如何在阿里云GPU云服务器上基于Alpaca大模型快速搭建个人版“对话大模型”。
【玩转AIGC系列】从0快速搭建个人版“对话大模型”