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 题意: 给出一个 ...
随机推荐
- matlab保存txt文件
save roadsurfacepointcloud.xyz -ascii roaddata2 %保存路面点云文件 roaddata2是变量.
- C语言实现队列(纯C)
1. [代码][C/C++]代码 #include <stdio.h>#include <stdlib.h>#define ElemType int #define Statu ...
- linux命令学习笔记(32):gzip命令
减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间. gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用.gzip不仅可以 ...
- CSS实现简单无缝滚动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 百度地图API的第一次接触——热区
1.代码很简单 var map = new BMap.Map("container"); var point = new BMap.Point(116.404, 39.915); ...
- AR/VR-VR-Info-Micron-Insight:虚拟现实开辟心理健康新途径
ylbtech-AR/VR-VR-Info-Micron-Insight:虚拟现实开辟心理健康新途径 1.返回顶部 1. 虚拟现实开辟心理健康新途径 全国心理疾病联盟最近发表的一份报告揭示了惊人的统计 ...
- 6 git 生成SSH公钥/私钥 查看公钥
如果没有公钥的话就生成公钥私钥: $ ssh-keygen 然后连续回车(一次是位置,两次密码)
- javascript getAttribute
var nodes = document.getElementsByTagName("script"); var node = nodes[nodes.length - 1]; v ...
- java 对象锁和类锁的区别(转)
java 对象锁和类锁的区别 转自; ) ); ; ) ); 上述的代码,第一个方法时用了同步代码块的方式进行同步,传入的对象实例是this,表明是当前对象,当然,如果需要同步其他对象实例,也不可 ...
- IIS PHP的Loaded Configuration File为空解决[转]
在Windows Server 2003上,IIS配置支持PHP,发现PHP扩展未加载,phpinfo()查看,显示 Configuration File (php.ini) Path (none) ...