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 水题.给原序列排序,如果此时合法则直接输出,否则 ...
随机推荐
- Python 辨异 —— __init__ 与 __new__
__init__ 更多的作用是初始化属性,__new__ 进行的是创建对象,显然 __new__ 要早于 __init__ 发生. 考虑一个继承自 tuple 的类,显然在 __init__ 无法对其 ...
- Hibernate4与hibernate3有错误的版本号的主要区别所造成的不一致
Hibernate版本号修改 Hibernate4的修改较大仅仅有spring3.1以上版本号可以支持,Spring3.1取消了HibernateTemplate,由于Hibernate4的事务管理已 ...
- 【Java】【Flume】Flume-NG阅读源代码AvroSink
org.apache.flume.sink.AvroSink是用来通过网络来数据传输的.能够将event发送到RPCserver(比方AvroSource),使用AvroSink和AvroSource ...
- 【书单】matlab 科学计算、数值分析以及数学物理问题
1. 数学计算 MATLAB数值计算 MATLAB之父 : 编程实践 2. 数学物理问题 高等应用数学问题的MATLAB求解(第3版)(豆瓣评价极好) 3. 模式识别
- ArcGIS Engine 中的多线程使用[转载]
一直都想写写AE中多线程的使用,但一直苦于没有时间,终于在中秋假期闲了下来.呵呵,闲话不说了,进入正题! 大家都了解到ArcGIS中处理大数据量时速度是相当的慢,这时如果你的程序是单线 ...
- CefSharp For WPF基本使用
原文:CefSharp For WPF基本使用 Nuget引用 CefSharp.Wpf CefSharp.Common cef.redist.x64 cef.redist.x86 直接搜索安装Cef ...
- ABP缓存示例
private readonly ICacheManager _cacheManager; public ProgrammeManage(ICacheManager cacheManager) { _ ...
- WPF学习笔记:(二)数据绑定模式与INotifyPropertyChanged接口
数据绑定模式共有四种:OneTime.OneWay.OneWayToSource和TwoWay,默认是TwoWay.一般来说,完成数据绑定要有三个要点:目标属性是依赖属性.绑定设置和实现了INotif ...
- WPF DataGrid的LoadingRow事件
<Window x:Class="DataGridExam.MainWindow" xmlns="http://schemas.microsoft.c ...
- AY的Dapper研究学习-基本入门-C#开发-aaronyang技术分享
原文:AY的Dapper研究学习-基本入门-C#开发-aaronyang技术分享 ====================www.ayjs.net 杨洋 wpfui.com ...