题目链接:https://codeforces.com/contest/1363/problem/A

题意

判断是否能从 $n$ 个数中选 $x$ 个数加起来和为奇数。

题解

首先 $n$ 个数中至少需要有 $1$ 个奇数,之后为了不影响和的奇偶性向余下 $x-1$ 个数中加入成对的奇数或单个偶数即可。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n, x; cin >> n >> x;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int t; cin >> t;
if (t & 1) ++odd;
else ++even;
}
if (odd == 0) cout << "No" << "\n";
else {
--x, --odd;
x -= 2 * min(x / 2, odd / 2);
cout << (even >= x ? "Yes" : "No") << "\n";
}
} int main() {
int t; cin >> t;
while (t--) solve();
}

Codeforces Round #646 (Div. 2) A. Odd Selection(数学)的更多相关文章

  1. Codeforces Round #646 (Div. 2) 题解 (ABCDE)

    目录 A. Odd Selection B. Subsequence Hate C. Game On Leaves D. Guess The Maximums E. Tree Shuffling ht ...

  2. Codeforces Round #575 (Div. 3) B. Odd Sum Segments (构造,数学)

    B. Odd Sum Segments time limit per test3 seconds memory limit per test256 megabytes inputstandard in ...

  3. Codeforces Round #646 (Div. 2) E. Tree Shuffling(树上dp)

    题目链接:https://codeforces.com/contest/1363/problem/E 题意 有一棵 $n$ 个结点,根为结点 $1$ 的树,每个结点有一个选取代价 $a_i$,当前 $ ...

  4. Codeforces Round #646 (Div. 2) C. Game On Leaves(树上博弈)

    题目链接:https://codeforces.com/contest/1363/problem/C 题意 有一棵 $n$ 个结点的树,每次只能取叶子结点,判断谁能最先取到结点 $x$ . 题解 除非 ...

  5. Codeforces Round #646 (Div. 2) B. Subsequence Hate(前缀和)

    题目链接:https://codeforces.com/contest/1363/problem/B 题意 可以将 $01$ 串中的 $0$ 变为 $1$.$1$ 变为 $0$,问至少需要变换多少字符 ...

  6. Codeforces Round #646 (Div. 2)【B. Subsequence Hate题解】

    具体思路已经在代码注释中给出,这里不再赘述. #include<iostream> #include<algorithm> using namespace std; int t ...

  7. Codeforces Round #646 (Div. 2)【C. Game On Leaves 题解】

    题意分析 关于这道题,意思就是两个人摘叶子,谁最后摘到编号为x的谁就赢了.既然是叶子,说明其最多只有一个分支,由于题目上说了是无向图,那就是度数小于等于的节点.也就是一步步移除度数小于等于的节点,直到 ...

  8. Codeforces Round #646 (Div. 2) C、Game On Leaves

    题目链接:C.Game On Leaves 题意: 给你一个n个节点的无根树,你每次可以删除一个叶节点.如果谁先删除x号节点谁就赢了.两个人轮流操作 题解: 如果x号节点本身就是一个叶节点,那么谁先走 ...

  9. Codeforces Round #646 (Div. 2) E. Tree Shuffling dfs

    题意: 给你n个节点,这n个节点构成了一颗以1为树根的树.每一个节点有一个初始值bi,从任意节点 i 的子树中选择任意k个节点,并按他的意愿随机排列这些节点中的数字,从而产生k⋅ai 的成本.对于一个 ...

随机推荐

  1. Centos 打开ssh 密码验证 和 root 登录

    # 1 打开系统的密码验证功能: vim /etc/ssh/sshd_config #允许使用密码登录(注释此行 就是允许证书登录) PasswordAuthentication yes # 2 打开 ...

  2. 【Linux】配置ssh留下的一些思考和大坑解决办法

    今天传包突然有问题,结果发现是ssh出现了问题,密钥也在里面,都是正常的,但是还有什么问题呢? 后来总结下需要注意点: 1.最开始你要检查.ssh/  这个文件夹的权限,看下权限是否为700或者为75 ...

  3. [从源码学设计]蚂蚁金服SOFARegistry之配置信息

    [从源码学设计]蚂蚁金服SOFARegistry之配置信息 目录 [从源码学设计]蚂蚁金服SOFARegistry之配置信息 0x00 摘要 0x01 业务范畴 1.1 配置作用 1.2 学习方向 0 ...

  4. postman接口测试之复制多个接口或collections到某个子文件夹或collections下

    一.痛点 1.postman只支持复制一个请求,或者一个子文件夹,但是不支持复制多个请求,或者整个collections到某个子文件夹或者某个collections下. 2.网上查了好一会儿,没有一个 ...

  5. Flask源码关于local的实现

    flask源码关于local的实现 try: # 协程 from greenlet import getcurrent as get_ident except ImportError: try: fr ...

  6. 转 10 jmeter之动态关联

    10 jmeter之动态关联   jmeter中关联是通过之前请求的后置处理器实现的,具体有两种方式:XPath Extractor(一般xml的时候用的多)和正则表达式提取器. 以webtours登 ...

  7. JavaScript中创建数组的方式!

    JavaScript中创建数组的方式! 利用数组字面量 // 1 直接量 console.log(Array.prototype); var arr = [1, 2, 4, 87432]; // 注意 ...

  8. CentOS7.9静默安装Oracle19C软件

    CentOS7.9静默安装Oracle19C软件 Oracle发布了支持的版本.可以看到了Oracle11gR2和Oracle12C.一直到2022年就不支持patch和服务.(感慨Oracle 11 ...

  9. XA Transactions

    XA Transactions XA is a two-phase commit protocol that is natively supported by many databases and t ...

  10. 签名 sign key 纸质邮件 历史 RSA诞生历史

    API接口签名校验,如何安全保存appsecret? - 知乎  https://www.zhihu.com/question/40855191 要保证一般的客户端-服务器通信安全,可以使用3个密钥. ...