A. Odd Selection

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值