题目链接: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. LINIX上Nginx的从零安装

    源码编译方式: #一般系统中已经装了了make和g++,无须再装 安装make: yum -y install autoconf automake make 安装g++: yum -y install ...

  2. CSS margin属性

    例子: p{ margin:2cm 4cm 3cm 4cm; } 结果如下: margin-top是上外边距 margin-right是右外边距 margin-bottom是下外边距 margin-l ...

  3. 2、什么是session?

    session 什么是Session?Session什么时候产生?    Session:在计算机中,尤其是在网络应用中,称为“会话控制”.Session 对象存储特定用户会话所需的属性及配置信息.这 ...

  4. 将.opt、.frm、.MYD、.MYI文件放入mysql

    问题:如果数据库没有给sql脚本而且给的.opt..frm..MYD..MYI这些文件,应该如何加载呢???? 解答:首先需要找到“mysql的安装目录/data/”,怎么找?mysql命令执行“sh ...

  5. python中字符串输出格式

    print输入格式总结 通过使用ljust(),center(),rjust()函数来实现输入字符串的左右对齐,居中,右对齐等操作; 方法一:(函数不带参数,则默认以空格填充,注意:文字与空格总字符数 ...

  6. 2018湘潭大学程序设计竞赛【E】

    题目链接:https://www.nowcoder.com/acm/contest/105/E 题意:给你美食种类和查询次数,告诉你美味度和价格,给你固定钱数,问你最多能吃到多少美味度的食物.(X真是 ...

  7. D3.js 区域生成器 (V3版本)

    区域生成器(Area Generator)   区域生成器(Area Generator)用于生成一块区域,使用方法与线段生成器类似.线段生成器地址:数据访问器有x().x0().x1().y().y ...

  8. 微信小程序picker下拉绑定数据

    页面部分 <picker mode = "selector" bindchange="bindPickerChange" value="{{pr ...

  9. 2018-6-17-win10-UWP-全屏

    title author date CreateTime categories win10 UWP 全屏 lindexi 2018-06-17 17:51:19 +0800 2018-2-13 17: ...

  10. Simple example of use of __setstate__ and __getstate__

    class Foo(object): def __init__(self, val=2): self.val = val def __getstate__(self): print ("I' ...