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 题意: 给出一个 ...
随机推荐
- 高效上网教程---资源软件搜索技巧(搜索好用软件或者app去哪些网站)
高效上网教程---资源软件搜索技巧(搜索好用软件或者app去哪些网站) 一.总结 一句话总结:查看下面这些网站用户推荐的 知乎:比如 小众软件 site:zhihu.com 简书:查看你需要的用户推荐 ...
- MD5算法的简单编写
package com.t_09; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; ...
- hdu-2169 Computer(树形dp+树的直径)
题目链接: Computer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- zero to one(1)
How to google 这两天把之前的过期的账号重新弄了一下,在vutrl上的账号,普通的话现在2.5$只提供ipv6地址,如果是想google我觉得这个应该没有什么问题,或者可以买***的账号, ...
- ubuntu svn 常用命令
1.svn svn update 更新 新增文件或文件夹并提交svn add "sss" test.py testw.pysvn add "dir" dir_p ...
- [转]从onload和DOMContentLoaded谈起
这篇文章是对这一两年内几篇dom ready文章的汇总(文章的最后会标注参考文章),因为浏览器进化的关系,可能他们现在的行为与本文所谈到的一些行为不相符.我也并没有一一去验证,所以本文仅供参考,在具体 ...
- C# 调用SQL的存储过程的接口及实现
1. 接口为ExecuteStoredProcedure(string storedProcedureName, params ObjectParameter[] parameters) 2. 参数为 ...
- WPF ValidationRule 触发ErrorTemplate 的注意事项
ValidationRule 验证时, 当验证失败后,再次验证成功, errorTemplate 还是触发, 不会被清掉. 因此需要主动调用 Validation.ClearInvalid(dtpTe ...
- shell expr 的使用注意事项
#!/bin/bash a=10 b=20 c=`expr $a + $b` echo "a + b :$c" c='expr $a + $b' echo "a + b ...
- 生成分布式随机ID
经测试,最快的一种 public class Generator { // should be between 40 (34 years) and 42 (139 years) ; // should ...