Codeforces Round #771 (Div. 2), problem: (B) Odd Swap Sort

 

 

Problem - B - Codeforces

就是给你个序列, 给他整成升序的, 每次操作可以使相邻两个数交换位置, 交换条件是二数之和为奇数

结果只需输出是否可以整成升序的

 

思路: 需要奇数偶数分开讨论, 如果奇数和偶数都分别是单增的那么可行, 反之为no

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
const int N = 1e5+10;
int a[N];
int main()
{
    int t;
    cin >> t;
    while(t --)
    {
        bool f =  0;
        int n;
        cin >> n;
        for(int i=0; i < n; i ++)cin >> a[i];
        
        int odd=0, even=0;
        for(int i = 0; i  <n; i ++)
        {
            if(a[i]%2)
            {
                if(odd>a[i])
                {
                    f=1;
                    break;
                }
                odd=a[i];
            }
            else
            {
                if(even>a[i])
                {
                    f=1;
                    break;
                }
                even=a[i];
            }
        }
        if(f)cout << "NO\n";
        else    cout << "YES\n";
    }
    return 0;
}

 

posted @ 2022-02-15 11:42  la-la-wanf  阅读(61)  评论(0编辑  收藏  举报