Codeforces Round #563 (Div. 2)B;Ehab Is an Odd Person

原文链接:任意门

题目大意:给你一组数,让你交换两个数的位置,让它们的和为奇数,且使其交换后,顺序满足最小字典序列。
思路:这就是一道狗题,看代码,你就会******了,只需要sort排序。
代码:

 1 #include"iostream"
 2 #include"algorithm"
 3 #include"cstdio"
 4 #include"cstring"
 5 long long a[10000006],n,js=0,os=0;
 6 using namespace std;
 7 int main(){
 8     std::ios::sync_with_stdio(false);
 9     cin>>n;
10     for(int i=0;i<n;i++) {
11         cin>>a[i];
12         if(a[i]%2!=0) js++;
13         else{
14             os++;
15         }
16     }
17     if(js!=0&&os!=0) sort(a,a+n);
18     for(int i=0;i<n;i++){
19         cout<<a[i];
20     if(i!=n-1){
21         cout<<" ";
22       }
23      }
24      return 0;
25 }

原文地址:https://www.cnblogs.com/huangdf/p/12222908.html

时间: 2024-11-02 08:54:17

Codeforces Round #563 (Div. 2)B;Ehab Is an Odd Person的相关文章

Codeforces Round #563 (Div. 2)C. Ehab and a Special Coloring Problem

原文链接:传送门思路:素数筛代码: 1 #include"iostream" 2 #include"algorithm" 3 #include"cstring" 4 using namespace std; 5 long long a[2000006],n; 6 int main(){ 7 cin>>n; 8 long long flag = 1; 9 memset(a,0,sizeof(a)); 10 for(int i=2;i&l

Codeforces Round #563 (Div. 2)/Codeforces1174

CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i\)与\(\sum\limits_{n+1}^{2n}a_i\)差值最大,排一下序就好了 CF1174B Ehab Is an Odd Person 一个显然的性质就是如果至少有一个奇数和一个偶数,那么是可以随意调整的,也就是升序排序 否则不可以进行任何操作 CF1174C Ehab and a Special Coloring Problem 把每个质数预处理出来,\(x

Codeforces Round #563 (Div. 2) D、Ehab and the Expected XOR Problem

D. Ehab and the Expected XOR Problem Given two integers n and x, construct an array that satisfies the following conditions: for any element ai in the array, 1≤ai<2^n there is no non-empty subsegment with bitwise XOR equal to 0 or x, its length l sho

Codeforces Round #563 (Div. 2)C

C. Ehab and a Special Coloring Problem 题目链接:http://codeforces.com/contest/1174/problem/C 题目 You're given an integer n. For every integer i from 2 to n, assign a positive integer ai such that the following conditions hold: For any pair of integers (i,

Codeforces Round #525 (Div. 2)A. Ehab and another construction problem

A. Ehab and another construction problem 题目链接:https://codeforc.es/contest/1088/problem/A 题意: 给出一个x,找出这样的a,b满足:1<=a,b<=x,并且a%b=0,a/b<x,a*b>x. 题解: 赛后发现,除开x=1的情况,其它情况a=b=x就可以满足条件了... 但还是附上比赛时候的代码吧... #include <bits/stdc++.h> using namespace

Codeforces Round #563 (Div. 2)

CF 题目链接:https://codeforces.com/contest/1174 总结 ABC都比较水,27分钟写完了,但是D题想偏了,一直WA,AC代码确实太巧妙了. A题 #include<bits/stdc++.h> using namespace std; #define ll long long #define N 100050 int n,sum1,sum2,a[N]; template<typename T>void read(T&x) { ll k=0

Codeforces Round 563 (Div. 2) 题解

自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则说明所有数相同,一定无解. 时间复杂度 $O(n\log n)$. #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> PII; const int maxn=

Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even

题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <vector> #include <algorithm> #define INF 0x3f3f3f3f #define mem(str,x) memset(str,(x),sizeof(str)

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i