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 perform the following operation on it as many times as you want:
- Pick two integers ii and jj (1≤i,j≤n)(1≤i,j≤n) such that ai+ajai+aj is odd, then swap aiai and ajaj.
What is lexicographically the smallest array you can obtain?
An array xx is lexicographically smaller than an array yy if there exists an index ii such that xi<yixi<yi, and xj=yjxj=yj for all 1≤j<i1≤j<i. Less formally, at the first index ii in which they differ, xi<yi
思路:
记录偶数和奇数的个数,只要数组内同时有偶数和奇数,无论几个都可以使数组完全排序。
代码:
#include <bits/stdc++.h> using namespace std; typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t; int a[MAXN]; int main()
{
cin >> n;
bool flag1 = false, flag2 = false;
for (int i = 1;i <= n;i++)
{
cin >> a[i];
if (a[i] % 2 == 0)
flag1 = true;
if (a[i] % 2 == 1)
flag2 = true;
}
if (flag1 && flag2)
sort(a+1, a+1+n);
for (int i = 1;i <= n;i++)
cout << a[i] << ' ';
cout << endl; return 0;
}
Codeforces Round #563 (Div. 2) B. Ehab Is an Odd Person的更多相关文章
- 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) 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) 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)/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)B
B.Ehab Is an Odd Person 题目链接:http://codeforces.com/contest/1174/problem/B 题目 You’re given an array a ...
- Codeforces Round #563 (Div. 2) A-D
A. Ehab Fails to Be Thanos 这个A题很简单,就是排个序,然后看前面n个数和后面的n个数是不是相同,相同就输出-1 #include <cstdio> #inclu ...
- Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula
F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树 ...
- Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem
E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...
随机推荐
- ffmpeg去水印
1.用potplayer打开有水印的视频文件,截图一张待用.2.用IrfanView打开保存的图片,调整到100%大小,按住鼠标左键框选水印位置,记下标题“Selection:”右边的4组数字.3.f ...
- MFC默认窗口类名称
// special AFX window class name mangling #ifndef _UNICODE #define _UNICODE_SUFFIX #else #define _UN ...
- linux 加载raid驱动
Driver Disk Installation Guide for ARC-11XX/ARC12XX/ARC16XX/18XX RAID Controller on RHEL 5.11 or Cen ...
- bzoj1177&p3625 [APIO2009]采油区域p[大力讨论]
我好菜菜啊. 给定矩形,从中选出三个边长K的正方形互不重叠,使得覆盖到的数总和最大. 想的时候往dp上钻去了..结果一开始想了一个错的dp,像这样 /************************* ...
- 解决mongodb查询慢的问题
最近项目上一直在用mongodb作为数据库,mongodb有他的优势,文档型类json格式存储数据,修改起来比传统的关系型数据库更方便,但是最近在用mongodb出现了查询缓慢的问题,我用命令行查询, ...
- 系列文章--突袭HTML5
学习新的网站构建技术:基于HTML5,但不限于HTML5. 突袭HTML5之Javascript API扩展5 - 其他扩展 突袭HTML5之Javascript API扩展4 - 拖拽 ...
- JAVA 编程思想二
1: java 单根继承的优点? 方便垃圾回收: 垃圾回收的设计会方便实现. 多重继承的函数重名的问题. 2: 向下转型和向上转型? 向下转型不安全,向上转型安全. 3: system.g ...
- WPF命令使用
What 命令包含以下部分: 命令:一个实现了ICommand接口的类,RoutedCommand是WPF里最常用的命令类,其它命令类大多派生自RoutedCommand 命令源:触发命令的对象,如b ...
- c#正则表达式替换
替换规则: 替换中包含原部分逐句,可以用分组的方式来替换,用?<组名>来标记需要记录的数据,在替换的时候使用 ${组名} 或者 <组名> 来加载这部分数据. 例如: 替换:&l ...
- SpringBoot使用拦截器无效
附上代码: public class WendaWebConfiguration extends WebMvcConfigurerAdapter { @Autowired PassportInterc ...