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]<<' ';
    }
  }
}
相关文章
|
3月前
|
存储 人工智能 监控
大模型训练、AI项目 的 GPU 云服务器价格多少?阿里云 EGS GPU 云服务器最新配置价格清单(小时/月/年)
阿里云 EGS GPU云服务器 为AI开发者、科研人员、企业团队提供了弹性、可按需租用的高性能GPU算力,覆盖从T4入门卡到L20高端显卡的完整实例矩阵,支持包年包月、按量付费、抢占式实例、节省计划多种计费方案,适配模型训练、AI推理、AIGC生成、科学仿真等多元化高性能计算场景。在评估 阿里云 EGS GPU云服务器 服务器成本时,不能只看实例本身标价,必须把云盘、公网带宽、快照等附加计费项纳入预算评估。借助nvidia-smi等本地检测命令,可以快速验证GPU硬件状态;通过阿里云CLI和Python监控脚本,能够实时查询账单,监控算力消耗,及时发现成本异常。
469 1
|
Kubernetes 安全 Linux
使用kubeadm快速部署一个k8s集群
使用kubeadm快速部署一个k8s集群
|
4月前
|
人工智能 缓存 自然语言处理
阿里云百炼节省计划与资源包详解:区别与选型指南、常见问题
本文解析了阿里云百炼平台的三大核心计费优化方案:AI通用型节省计划、其他模型节省计划与资源包。文章首先通过选型指南对比了各方案的适用场景与核心差异,指出AI通用型节省计划(承诺月消费换取阶梯折扣,最高5.3折)因其覆盖广、灵活度高,是长期多模型混合调用场景下的首选。随后详细阐述了AI通用型节省计划的抵扣逻辑(免费额度→资源包→其他模型节省计划→AI通用型节省计划→按量付费)、生效规则、折扣计算及生命周期管理。
|
4月前
|
人工智能 编解码 安全
我把电脑外包给豆包后,效率飞升!【附教程】
看完这篇,你将比99%的人更会用豆包~
1330 0
|
12月前
|
存储 关系型数据库 数据处理
2核4G配置云服务器价格多少钱?阿里云2核4G云服务器优惠活动价格及综合测评
在云计算应用场景中,2 核 4G 配置的云服务器因兼顾性能与成本,成为个人开发者、初创企业及中小型团队的高频选择。本文基于 阿里云最新产品信息,从价格体系、性能表现、适用场景等维度,对 2 核 4G 配置的云服务器进行全面解析,为用户选型提供客观参考。
|
应用服务中间件 PHP nginx
今日小结通过aliyun的本地容器镜像部署我的nginx和php环境
简介: 本教程介绍如何基于 Dragonwell 的 Ubuntu 镜像创建一个运行 Nginx 的 Docker 容器。首先从阿里云容器镜像服务拉取基础镜像,然后编写 Dockerfile 确保 Nginx 作为主进程运行,并暴露 80 端口。最后,在包含 Dockerfile 的目录下构建自定义镜像并启动容器,确保 Nginx 在前台运行,避免容器启动后立即退出。通过 `docker build` 和 `docker run` 命令完成整个流程。
805 25
今日小结通过aliyun的本地容器镜像部署我的nginx和php环境
|
缓存 前端开发 JavaScript
性能测试指标拟定参考
本文介绍性能测试关键指标与实施要点,涵盖用户数、业务量、核心场景及性能指标(如TPS、响应时间、波动率)的调查方法,指导如何科学评估系统处理能力与稳定性。
|
开发框架 .NET C#
如何判断一个 Dot Net 程序是 32 位还是 64 位?
如何判断一个 Dot Net 程序是 32 位还是 64 位?
|
机器学习/深度学习 存储 文字识别
阿里国际Ovis2系列模型开源:多模态大语言模型的新突破
阿里国际Ovis2系列模型开源:多模态大语言模型的新突破
1043 0
|
测试技术 数据库连接 API
反向海淘南美市场:Cssbuy 淘宝代购集运系统搭建攻略
宝子们,反向海淘面向南美市场火爆!本文由Taobaoapi2014供稿,分享Cssbuy淘宝代购集运系统的搭建攻略。系统旨在为南美用户提供淘宝商品代购和集运服务,具备商品搜索、下单、支付、物流跟踪等功能,并支持多语言。服务器选择阿里云或腾讯云,安装Web服务器、PHP及数据库环境。下载并上传Cssbuy源码,配置数据库连接,完成系统安装与初始化。对接淘宝API,进行功能和安全测试后正式上线。按此攻略操作,轻松开启南美反向海淘业务!