题目链接:http://codeforces.com/problemset/problem/1174/B

题意:给定长度 n 的数组,任意俩个相加为奇数的数可以交换数组中的位置,让这个数组尽量从小到大。

思路:不难发现只要 2 个数奇偶性不同就可以交换 ,对于纯奇数或纯偶数数组,它们是没办法交换任何数,原样输出即可。不是纯奇偶的数组,可以把任意的数换至你想要的位置,所以将数组 sort 排序输出即可。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 +;
int n;
int a[maxn];
int main()
{
scanf("%d",&n);
bool flag = false;
for(int i = ;i < n;i++)
{
scanf("%d",&a[i]);
if(i&&!flag){
if(a[i]% != a[i-]%)
flag = true;
}
}
if(flag)
{
sort(a,a+n);
for(int i = ;i < n;i++) printf("%d ",a[i]);
}
else for(int i = ;i < n;i++) printf("%d ",a[i]);
return ;
}

Codeforces 1174B Ehab Is an Odd Person的更多相关文章

  1. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  2. 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 ...

  3. Codeforces 1088E Ehab and a component choosing problem

    Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...

  4. codeforces#1157D. Ehab and the Expected XOR Problem(构造)

    题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...

  5. Codeforces 1174C Ehab and a Special Coloring Problem

    题目链接:http://codeforces.com/problemset/problem/1174/C 题意:给你一个n,要你填充 下标由2 ~ n 的数组ai,要求下标互质的俩个数不能相等,并且数 ...

  6. Codeforces 1174A Ehab Fails to Be Thanos

    题目链接:codeforces.com/problemset/problem/1174/A 题意:给定长度2n 的数组,改变数组顺序,使得前 n 个数的和不等于 后 n 个数的和,不行输出-1. 思路 ...

  7. [Codeforces1174B]Ehab Is an Odd Person

    题目链接 https://codeforces.com/contest/1174/problem/B 题意 给一个数组,只能交换和为奇数的两个数,问最终能得到的字典序最小的序列. 题解 内心OS:由题 ...

  8. CodeForces 621A Wet Shark and Odd and Even

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #inclu ...

  9. Codeforces.1088D.Ehab and another another xor problem(交互 思路)

    题目链接 边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→) 首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\)). 然后发现我们是可以逐位比较出\(a,b\ ...

随机推荐

  1. 芜湖市2018市队选拔Day2T1

    好激动啊,Day2竟然AK了! Day2T1养宠物 Descriptionbadgers是可爱的动物,Smart想拥有一些.宠物店提供N个badgers,编号为1..N,Smart都很喜欢,所以他想拥 ...

  2. delphi INI文件

    INI 文件读写 filecreate('路径加文件名')://创建一个文件. (1) INI文件的结构: ;这是关于INI文件的注释部分 [节点] 关键字=值 ... INI文件允许有多个节点,每个 ...

  3. ionic学习使用笔记(一) 版本更新及创建项目时遇到的问题解决

    最近开始用ionic开发项目,虽然去年的时候用ionic 2.0 开发过公司的项目,不过现在的ionic已经升级到了ionic framework 3.0 了.而且还有个 ionic-cli . 使用 ...

  4. Invoking destroy method 'close' on bean with name 'dataSource'

    Invoking destroy method 'close' on bean with name 'dataSource' Spring与Mybatis整合时出现的问题,找了一晚上结果是一个属性写错 ...

  5. 树莓派安装omv

    1.Win32DiskImager写入光盘镜像 2.进入omv页面 设置 ip 端口号 ,设置时间,设置ssh打开,设置会话超时时间 ××××设置 dns  很重要!! #这里用的是阿里云的DNS服务 ...

  6. POJ 3468 A Simple Problem with Integers (分块)

    Description You have \(N\) integers, \(A_1, A_2, ... , A_N\). You need to deal with two kinds of ope ...

  7. HDU 6651 Final Exam (思维)

    2019 杭电多校 7 1006 题目链接:HDU 6651 比赛链接:2019 Multi-University Training Contest 7 Problem Description Fin ...

  8. 35-Ubuntu-组管理-01-添加组/删除组/确认组信息

    组管理 提示: 创建组/删除组的终端命令都需要sudo执行,标准用户没有权限! 序号 命令 作用 01 sudo groupadd 组名 添加组 02 sudo groupdel 组名 删除组 03 ...

  9. 【gcc】更新下载编译gcc遇到的各种问题

    帮学长的oj升级gcc版本.遇到了贼多问题.. [悲惨的开始] 安装gcc版本推荐ustc的mirror的下载,超快der... https://mirrors.ustc.edu.cn/gnu/gcc ...

  10. http://localhost:8080 is requesting your username and password

    after you startup your tomcat,  you type a concrete request url  in broswer, the tomcat probably wil ...