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;
}

Codeforces Round #771 (Div. 2), problem: (B) Odd Swap Sort的更多相关文章

  1. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  2. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

  3. Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation

    还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门  Problem - D - Codeforces 题意 n个数字,n ...

  4. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  5. Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学

    — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...

  6. Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)

    Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...

  7. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  8. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  9. Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...

随机推荐

  1. docker是干什么的,docker常用命令

    镜像下载.域名解析.时间同步请点击 阿里云开源镜像站 一.百度百科 Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖到一个可移植的镜像中,然后发布到任何流行的Linux或Win ...

  2. Oracle视图、存过、包、方法赋予/收回权限给用户

    oracle给某用户授权/回收视图查询 赋权: grant select on $_view to $_user; 这样 $_user用户就拥有了查询$_view视图的权限了 回收: revoke s ...

  3. .Net Core 实现账户充值,还款,用户登录(WebApi的安全)

    个人未开通网站: http://justin1107.pc.evyundata.cn/vip_justin1107.html Api using System; using System.Collec ...

  4. Spring---Spring专题(二)

    1.Spring配置数据源 1.1 数据源(连接池)的作用 数据源(连接池)是提高程序性能而出现的 事先实例化数据源,初始化部分链接资源 使用连接资源时从数据源中获取 使用完毕后将连接资源归还给数据源 ...

  5. python3 使用mongo数据库

    0让服务器端开启服务 sudo mongod --port 27017 --dbpath /data/db --logpath /data/log --logappend --fork --auth ...

  6. Java Byte不能用equals

  7. java反射和动态代理实现与原理详细分析

    关于Java中的动态代理,我们首先需要了解的是一种常用的设计模式--代理模式,而对于代理,根据创建代理类的时间点,又可以分为静态代理和动态代理. 一.代理模式    代理模式是常用的java设计模式, ...

  8. memcacuery cache 相比,有什么优缺点?

    把 memcached 引入应用中,还是需要不少工作量的.MySQL 有个使用方便的 query cache,可以自动地缓存 SQL 查询的结果,被缓存的 SQL 查询可以被反复 地快速执行.Memc ...

  9. Redis 的持久化机制是什么?各自的优缺点?

    Redis 提供两种持久化机制 RDB 和 AOF 机制: 1.RDBRedis DataBase)持久化方式: 是指用数据集快照的方式半持久化模式) 记录 redis 数据库的所有键值对,在某个时间 ...

  10. Windows10安装PHP7+Apache 2.4

    下载下面的文件 httpd-2.4.39-win64-VC15.zip php-7.3.4-Win32-VC15-x64.zip 如果下载失效,从这里下载 https://windows.php.ne ...