A. Odd Selection
A.奇数选择
time limit per test: 1 second
每次测试的时间限制:1秒
memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节
input: standard input
输入:标准输入
output: standard output
产出:标准产出
Shubham has an array a of size n, and wants to select exactly x elements from it, such that
Shubham有一个大小为n的数组,并且希望从其中精确地选择x元素,这样
their sum is odd. These elements do not have to be consecutive. The elements of the array are
their sum is odd. These elements do not have to be consecutive. The elements of the array are
not guaranteed to be distinct.
不能保证是不同的。
Tell him whether he can do so.
告诉他他是否能做到。
Input
输入
The first line of the input contains a single integert(1 < t < 100)- the number of test
输入的第一行包含一个整数(1<t<100)–测试的数量
cases. The description of the test cases follws.
案子。测试用例的描述如下。
The first line of each test case contains two integers n andx(1≤x < n≤1000)- - - the
The first line of each test case contains two integers n andx(1≤x < n≤1000)- - - the
length of the array and the number of elements you need to choose.
数组的长度和需要选择的元素数。
The next line of each test case contains n integers a,a2…,an(1 < ai≤1000)-
The next line of each test case contains n integers a,a2…,an(1 < ai≤1000)-
elements of the array.
数组的元素。
Output
输出量
For each test case, print “Yes” or “No” depending on whether it is possible to choose x
For each test case, print “Yes” or “No” depending on whether it is possible to choose x
elements such that their sum is odd.
使它们的和是奇数的元素。
You may print every letter in any case you want.
在任何情况下,你都可以打印每封信。
小学数学
int main()
{
int t, n, x, i;
scanf("%d", &t);
while (t--)
{
cin>>n>>x;
int a[1001], k = 0, l = 0;
for (i = 0; i<n; i++)
{
cin>>a[i];
if (a[i] % 2 == 0)
k += 1;
else
l += 1;
}
if (k == 0)
{
if (x % 2 != 0)
cout<<"Yes\n";
else
cout<<"No\n";
}
else if (l == 0)
cout<<"No\n";
else if (l % 2 != 0)
cout<<"Yes\n";
else if (x != n)
cout<<"Yes\n";
else
cout<<"No\n";
}
return 0;
}