Codeforces 1174B Ehab Is an Odd Person
题目链接: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的更多相关文章
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- 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 ...
- Codeforces 1088E Ehab and a component choosing problem
Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...
- codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
- Codeforces 1174C Ehab and a Special Coloring Problem
题目链接:http://codeforces.com/problemset/problem/1174/C 题意:给你一个n,要你填充 下标由2 ~ n 的数组ai,要求下标互质的俩个数不能相等,并且数 ...
- Codeforces 1174A Ehab Fails to Be Thanos
题目链接:codeforces.com/problemset/problem/1174/A 题意:给定长度2n 的数组,改变数组顺序,使得前 n 个数的和不等于 后 n 个数的和,不行输出-1. 思路 ...
- [Codeforces1174B]Ehab Is an Odd Person
题目链接 https://codeforces.com/contest/1174/problem/B 题意 给一个数组,只能交换和为奇数的两个数,问最终能得到的字典序最小的序列. 题解 内心OS:由题 ...
- CodeForces 621A Wet Shark and Odd and Even
水题 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #inclu ...
- Codeforces.1088D.Ehab and another another xor problem(交互 思路)
题目链接 边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→) 首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\)). 然后发现我们是可以逐位比较出\(a,b\ ...
随机推荐
- Confluence 6 站点备份和恢复
Atlassian 推荐针对生产环境中安装使用的 Confluence 使用原始数据库工具备份策略. 在默认的情况下,Confluence 每天都会备份所有数据和附件到 XML 文件备份中.这些文件被 ...
- js和php语法区别
参考 : https://www.wangjingxian.cn/php/51.html
- Tomcat服务器配置参考
Coyote HTTP/1.1 Connector 概述 Coyote HTTP/1.1 Connector元素是一个支持HTTP/1.1协议的Connector组件.它使Catalina除了能够执行 ...
- fatal error C1047: 对象或库文件“.\x64\Release\Des.obj”是使用比创建其他对象所用编译器旧的编译器创建的;请重新生成旧的对象和库
问题描述: 在把一个32位的dll编译成64位的时候提示上面的错误 解决办法: >属性->常规->项目默认值->全程序优化 将这里的默认项 "使用链接时间代码生成& ...
- 23、css的定位问题
1.positon:relative相对定位 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...
- 3.5 compose redux sages
基于 redux-thunk 的实现特性,可以做到基于 promise 和递归的组合编排,而 redux-saga 提供了更容易的更高级的组合编排方式(当然这一切要归功于 Generator 特性), ...
- Mysql DBA
1 mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when dumping table `tb_co ...
- 2018 ECNA Regional Contest J. Watch Where You Step
题目链接:Watch Where You Step 题意 给定有向图的邻接矩阵,现在需要给该图增加边,使得如果两点可达必直接可达,求需要加边的数量. 题解 首先,如果给定 \(n\) 个结点的图中任意 ...
- webpack中代理配置(proxyTable)
注:用axios请求 1,下载axios npm i axios --save 2,在config文件下的index.js中配置代理地址 参考:https://vuejs-templates.gith ...
- hdu6319 Ascending Rating /// 单调队列
题目大意: 给定n m k,p q r mod, 给出序列的前k项 之后的按公式 a[i]=(p×a[i-1]+q×i+r)%mod 递推 求序列中每个长度为m的连续区间的 该区间最大值与第一位的位置 ...