首页 > 其他 > 详细

B. Ehab Is an Odd Person

时间:2019-06-04 13:51:07      阅读:167      评论:0      收藏:0      [点我收藏+]

链接: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 j(1i,jn)(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 1j<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;
}

  

B. Ehab Is an Odd Person

原文:https://www.cnblogs.com/YDDDD/p/10972861.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!