链接:https://codeforces.com/contest/1174/problem/B

题意:

You're given an array aa of length nn. You can perform the following operation on it as many times as you want:

  • Pick two integers ii and jj (1≤i,j≤n)(1≤i,j≤n) such that ai+ajai+aj is odd, then swap aiai and ajaj.

What is lexicographically the smallest array you can obtain?

An array xx is lexicographically smaller than an array yy if there exists an index ii such that xi<yixi<yi, and xj=yjxj=yj for all 1≤j<i1≤j<i. Less formally, at the first index ii in which they differ, xi<yi

思路:

记录偶数和奇数的个数,只要数组内同时有偶数和奇数,无论几个都可以使数组完全排序。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t; int a[MAXN]; int main()
{
cin >> n;
bool flag1 = false, flag2 = false;
for (int i = 1;i <= n;i++)
{
cin >> a[i];
if (a[i] % 2 == 0)
flag1 = true;
if (a[i] % 2 == 1)
flag2 = true;
}
if (flag1 && flag2)
sort(a+1, a+1+n);
for (int i = 1;i <= n;i++)
cout << a[i] << ' ';
cout << endl; return 0;
}

  

最新文章

  1. 关于RSA加密算法的长度限制问题
  2. PHP防SQL注入不要再用addslashes和mysql_real_escape_string
  3. SVN简介
  4. udp通信的原理---makefile文件
  5. UIWebView获得内容的高-作出自适应高的UIWebView
  6. mysql给日期增减
  7. 有一种风格,叫做 Low Poly 3D
  8. Collections.synchronizedMap 详解
  9. Heritrix个性化设置抓取目标
  10. hdu_2110_Crisis of HDU(母函数)
  11. Android关于AutoService、Javapoet讲解
  12. [UVa-437] Color Length
  13. [Swift]LeetCode629. K个逆序对数组 | K Inverse Pairs Array
  14. 分类器、logistic回归
  15. Redis Cluster [WARNING] Node 127.0.0.1:7003 has slots in migrating state (15495).
  16. 微信小程序开发--路由切换,页面重定向
  17. HDU 4725 The Shortest Path in Nya Graph(构图)
  18. 学习笔记37—WIN7系统本地连接没有有效的IP地址 电脑本地连接无有效ip配置怎么办
  19. Http Header Content-Typ
  20. Java语法基础学习DaySix

热门文章

  1. Hadoop- 流量汇总程序之如何实现hadoop的序列化接口及代码实现
  2. 【详解】苹果AppStore审核被拒,原因终逃不过这些!
  3. 分享知识-快乐自己:Excel快速导入Oracle 数据库
  4. 企业安全建设之搭建开源SIEM平台(上)
  5. 【C】四则运算生成和核对器----by郁卓、谢明浩
  6. listen 67
  7. 每天一个Linux命令(2):ls命令
  8. tyvj1659救援队——最小生成树
  9. g2o中setparameterid(0,0)方法
  10. 在多台手机上批量安装apk