题目链接: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. C#简单游戏外挂制作(以Warcraft Ⅲ为例)

    网上有很多外挂制作的教程,大多是讲针对大型网络游戏的,主要包含一些抓包.反汇编.C++的知识综合.事实也如此,常见的外挂都是使用VC++写的,从来没有过C#或者其他.NET语言编写的外挂. 作为微软. ...

  2. LInux文件基础知识和文件目录操作(系统调用函数方式)

    1.进程是处于活动状态的程序,某个用户通过操作系统运行程序所产生的进程代表着该用户的行为.如果用户不具备访问某个目录和文件的权限,那么该用户的进程也不能访问. 2.Linux系统中文件安全机制是通过给 ...

  3. 超好用的thinkphp5.0/thinkphp5.1分页插件!详细使用步骤(内附代码)

    效果 tp5.0使用方法 page下载地址:进入下载页面 提取码:s75k 1,把page文件夹整个目录复制到 目录extend下 2,修改默认配置 app/config.php 把里面的 'pagi ...

  4. 记录解决java.io.IOException: Server returned HTTP response code: 500 for URL:xxxxxxxx

    踩坑经历 因为项目需要去对接别的接口,使用URLConnection POST请求https接口,发送json数组时遇到java.io.IOException: Server returned HTT ...

  5. git分布式版本控制系统权威指南学习笔记(六):git reset、get stash、git checkout总结

    文章目录 1. 概述 2. 如何把修改暂存起来,留着以后使用? 2.1 使用场景 2.2 git stash 暂存进度 2.3 查看进度 2.4 恢复进度 3. 如何撤销工作区的修改? 4. 如何把暂 ...

  6. 13、testng.xml对用例进行分组

    目录如下: TestGroup.java 代码如下: package com.testng.cn; import org.testng.annotations.*; import static org ...

  7. spring4.3.5基本配置

    1.去官网下载必要的jar包,以及: 2.新建一个web项目,在Window->Java->Build Path->User Libraries 按照步骤1,2把spring的jar ...

  8. 洛谷 P1613 跑路 (倍增 + DP + 最短路)

    题目链接:P1613 跑路 题意 给定包含 \(n\) 个点和 \(m\) 条边的有向图,每条边的长度为 \(1\) 千米.每秒钟可以跑 \(2^k\) 千米,问从点 \(1\) 到点 \(n\) 最 ...

  9. POJ 3805 Separate Points (判断凸包相交)

    题目链接:POJ 3805 Problem Description Numbers of black and white points are placed on a plane. Let's ima ...

  10. upc组队赛2 Master of GCD 【线段树区间更新 || 差分】

    Master of GCD 题目描述 Hakase has n numbers in a line. At fi rst, they are all equal to 1. Besides, Haka ...