Codeforces Round #563 (Div. 2)B
B.Ehab Is an Odd Person
题目链接:http://codeforces.com/contest/1174/problem/B
题目
You’re given an array a of length n. You can perform the following operation on it as many times as you want:
Pick two integers i and j (1≤i,j≤n) such that ai+aj is odd, then swap ai and aj.
What is lexicographically the smallest array you can obtain?
An array x is lexicographically smaller than an array y if there exists an index i such that xi<yi, and xj=yj for all 1≤j<i. Less formally, at the first index i in which they differ, xi<yi
Input
The first line contains an integer n
(1≤n≤105) — the number of elements in the array a.
The second line contains n space-separated integers a1, a2, …, an (1≤ai≤109) — the elements of the array a.
Output
The only line contains n
space-separated integers, the lexicographically smallest array you can obtain.
Example
input
3
4 1 7
output
1 4 7
题意
给你一个长度为a的数组,选择两个数之和为奇数,可以交换这两个数,要使得这个数组字典序最小,输出变换后的这个数组。
思路
计算奇数和偶数的个数,一旦只有奇数或者只有偶数,则不存在两个数之和为奇数,故直接将原来数组输出就行,
只要都存在奇数或者偶数,则可以通过各种调法调成单调递增的数组,所以只要将其排序后输出即可。
//
// Created by hjy on 19-6-4.
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+;
int main()
{
int n;
while(cin>>n)
{
ll a[maxn];
bool flag= false,flag1=false;
for(int i=;i<n;i++)
{
cin>>a[i];
if(a[i]&)
flag=true;
else
flag1=true; }
if(flag&&flag1)
sort(a,a+n);
copy(a,a+n,ostream_iterator<ll>(cout," "));
cout<<endl;
}
return ;
}
Codeforces Round #563 (Div. 2)B的更多相关文章
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem
链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer i ...
- Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person
链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...
- Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos
链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...
- Codeforces Round #563 (Div. 2)C
C. Ehab and a Special Coloring Problem 题目链接:http://codeforces.com/contest/1174/problem/C 题目 You're g ...
- Codeforces Round #563 (Div. 2)A
A. Ehab Fails to Be Thanos 题目链接:http://codeforces.com/contest/1174/problem/A 题目 You’re given an arra ...
- Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...
- Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale
后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...
- Codeforces Round 563 (Div. 2) 题解
自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...
随机推荐
- 制作一个简单的WPF图片浏览器
原文:制作一个简单的WPF图片浏览器 注:本例选自MSDN样例,并略有改动.先看效果: 这里实现了以下几个功能:1. 对指定文件夹下所有JPG文件进行预览2. 对选定图片进行旋转3. 对选定图片 ...
- Analysis of variance(ANOVA)
方差分析,也称为"变异数分析",用于两个及两个以上样本均值(group means)差别的显著性检验.在 ANOVA 的环境下,一个观测得到的方差视为是由不同方差的源组合而成.
- JDBC学习笔记——事务、存储过程以及批量处理
1.事务 1.1.事务的基本概念和使 ...
- 基于VC面部识别软件(识别出人脸特征)
最近在学校MFC和Opencv,毕业只是做面部识别软件,所以写一个,我觉得很简单. 第一个VC组态opencv.不用说.非常easy,网上资料非常多,然后就是设计界面啦,这个全然凭个人喜好了,我设计的 ...
- wpf实现两头渐窄的线条效果
原文:wpf实现两头渐窄的线条效果 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/800 ...
- WPF与缓动(四) 弧形缓动
原文:WPF与缓动(四) 弧形缓动 WPF与缓动(四) 弧形缓动 ...
- Python 实现 淘宝秒杀 聚划算 自己主动提醒 源代码
说明 本实施例可以监视一起购买的成本button,当警报济济一堂花费时间整点到达(音频文件自定义位置)而自己主动跳出页面(URL习惯). 同一时候还能够通过命令行參数自己定义刷新间隔时间(默认0.1s ...
- AngularJS 计时器
<div ng-controller="MyController"> <!--显示$scope.clock的now属性--> <h1>hello ...
- 更改开机默认不显示explorer.exe,直接启动自己写的EXE程序方法
原文:更改开机默认不显示explorer.exe,直接启动自己写的EXE程序方法 更改开机默认不显示explorer.exe,直接启动自己写的EXE程序的函数: bool UpdateWinlogon ...
- MVC WebApi的两种访问方法
//UserInfoController using ClassLibrary; using System;using System.Collections.Generic;using System. ...