codeforces A. Odd Selection
程序员文章站
2022-07-15 16:16:49
...
题目
题意:
给你个元素,问这些元素是能否选择个数字,使得最后的元素和是个奇数。
思路:
如果是偶数的话,偶数的话无论加上多少对于原来的奇偶性是没有影响的,所以我们可以直接暴力出奇数个的时候,然后看看偶数能不能把缺的部分补上。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
int xxxxxxxxx = 1;
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}
inline void debug(ll x) {cout << xxxxxxxxx++ << " " << x << endl;}
inline void debugs(string s) {cout << s << endl;}
int main() {
int t;
read(t);
while (t--) {
int n, x, cnt1 = 0, cnt0 = 0, m;
read(n), read(x);
for (int i = 0; i < n; i++) {
read(m);
if (m & 1) cnt1++;
else cnt0++;
}
bool flag = true;
for (int i = 1; i <= cnt1 && i <= x; i += 2) {
if (x - i <= cnt0) {
flag = false;
break;
}
}
if (flag) printf("No\n");
else printf("Yes\n");
}
return 0;
}
上一篇: ZOJ - 3939 The Lucky Week【简单方法】
下一篇: 234.回文链表
推荐阅读
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Codeforces Round #686 (Div. 3) A. Special Permutation
-
Codeforces A. Sign Flipping (思维 / 构造) (Global Round 9)
-
codeforces A. Sum of Odd Integers
-
A. Add Odd or Subtract Even(思维题) Codeforces Round #624 (Div. 3)
-
Codeforces 1327 A. Sum of Odd Integers
-
codeforces A. Odd Selection
-
【Codeforces Global Round 7】A. Bad Ugly Numbers 题解
-
Codeforces Global Round 7 A. Bad Ugly Numbers