题目地址

        http://codeforces.com/contest/1196/problem/B

    

    

B. Odd Sum Segments
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array aa consisting of nn integers a1,a2,…,ana1,a2,…,an. You want to split it into exactly kk non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the nn elements of the array aa must belong to exactly one of the kk subsegments.

Let's see some examples of dividing the array of length 55 into 33 subsegments (not necessarily with odd sums): [1,2,3,4,5][1,2,3,4,5] is the initial array, then all possible ways to divide it into 33 non-empty non-intersecting subsegments are described below:

  • [1],[2],[3,4,5][1],[2],[3,4,5];
  • [1],[2,3],[4,5][1],[2,3],[4,5];
  • [1],[2,3,4],[5][1],[2,3,4],[5];
  • [1,2],[3],[4,5][1,2],[3],[4,5];
  • [1,2],[3,4],[5][1,2],[3,4],[5];
  • [1,2,3],[4],[5][1,2,3],[4],[5].

Of course, it can be impossible to divide the initial array into exactly kk subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.

You have to answer qq independent queries.

Input

The first line contains one integer qq (1≤q≤2⋅1051≤q≤2⋅105) — the number of queries. Then qq queries follow.

The first line of the query contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the number of elements in the array and the number of subsegments, respectively.

The second line of the query contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the ii-th element of aa.

It is guaranteed that the sum of nn over all queries does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑n≤2⋅105).

Output

For each query, print the answer to it. If it is impossible to divide the initial array into exactly kk subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as kk integers r1r1, r2r2, ..., rkrk such that 1≤r1<r2<⋯<rk=n1≤r1<r2<⋯<rk=n, where rjrj is the right border of the jj-th segment (the index of the last element that belongs to the jj-th segment), so the array is divided into subsegments [1;r1],[r1+1;r2],[r2+1,r3],…,[rk−1+1,n][1;r1],[r1+1;r2],[r2+1,r3],…,[rk−1+1,n]. Note that rkrk is always nn but you should print it anyway.

Example
input

Copy
3
5 3
7 18 3 14 1
5 4
1 2 3 4 5
6 2
1 2 8 4 10 2
output

Copy
YES
1 3 5
NO
NO     题意: 给定一个n,m。下一行有n个数。问是否可以分割成m组,使每组的和为奇数。如果可以,打印YES,并且输出分割出来的每组的最右边坐标(可能有多种,打印一组即可);否则输出“NO”;
    解析: 首先明确一点:偶数+奇数==奇数    奇数+奇数=偶数;
        所以呢,在给定的一组数中可以忽略偶数的存在,因为偶数与奇数的运算并不能改变结果的奇偶性。首先统计奇数的个数ob。要分成m组,假设每一组1个奇数,则至少需要m个奇数,因为偶数的存在改变不了结局。
    如果奇数个数ob比m还少,肯定分不出来m组。所以要ob>=m; 根据贪心的思想,从前往后分割。在前面,只要for到一个奇数,就算分割到一组,直到还剩最后一组。需要看最后一组奇数个数,ob-(k-1)即为剩余奇数个数
    如果是偶数个,肯定不行因为加起来是偶数,输出“NO”;奇数个的话,输出YES,打印最后一位的坐标,就行了。
   
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=;
typedef long long ll;
ll a[maxn];
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,m;
cin>>n>>m;
ll od=;
for(int i=;i<n;i++)
{
cin>>a[i];
if(a[i]%!=)
od++;    //统计奇数个数
}
if(od>=m&&(od-(m-))%!=)
{
cout<<"YES"<<endl;
ll k=;
for(int i=;i<n;i++)
{
if(a[i]%!=)
{
k++;  //当前所分的组数
if(k==m)
{
cout<<n<<endl;break;
}
else
{
cout<<i+<<" ";
}
}
}
// cout<<endl;
}
else
cout<<"NO"<<endl;
}
return ;
}

最新文章

  1. linux的sysctl基本配置
  2. oracle,sqlserver同一个表两个字段和成一个列查询 (详询请加qq:2085920154)
  3. Material Design - CollapsingToolbarLayout
  4. c# 程序检测日志输出的类
  5. Hadoop配置文件
  6. iOS-JS交互 (WebViewJavascriptBridge)
  7. linux网络编程中阻塞和非阻塞socket的区别
  8. xmlns 属性
  9. 关于java对象的思考
  10. android学习——环境搭建之HelloWorld
  11. MVVM模式
  12. Catch That Cow(BFS)
  13. leetcode — linked-list-cycle-ii
  14. linux查看和修改PATH环境变量的方法
  15. osx免驱网卡推荐
  16. Ruby http/net 中连接超时问题
  17. Spark思维导图之Spark SQL
  18. 重新学习Servlet二
  19. git学习(七):git 对象库
  20. 格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: GetLzdtArticleResult。InnerException 消息是“反序列化对象 属于类型 lzdt.DTO.Dtolzdt[] 时出现错误。读取 XML 数据时,超出最大

热门文章

  1. windows下移植别人配置好的python环境
  2. servlet的基本类和接口
  3. 吴裕雄--天生自然C++语言学习笔记:C++ 预处理器
  4. Python MongoDB 创建数据库
  5. Node.js NPM 管理包
  6. java基础源码 (1)--String类
  7. Tomcat JDK MySql 安装配置
  8. oracle函数创建与调用
  9. SOA--基于银行系统实例分析
  10. python期末复习—列表