C. Devu and Partitioning of the Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him?

Given an array consisting of distinct integers. Is it possible to partition the whole array into k disjoint non-empty parts such that p of the parts have even sum (each of them must have even sum) and remaining k - p have odd sum? (note that parts need not to be continuous).

If it is possible to partition the array, also give any possible way of valid partitioning.

Input

The first line will contain three space separated integers nkp (1 ≤ k ≤ n ≤ 105; 0 ≤ p ≤ k). The next line will contain n space-separated distinct integers representing the content of array aa1, a2, ..., an (1 ≤ ai ≤ 109).

Output

In the first line print "YES" (without the quotes) if it is possible to partition the array in the required way. Otherwise print "NO" (without the quotes).

If the required partition exists, print k lines after the first line. The ith of them should contain the content of the ith part. Print the content of the part in the line in the following way: firstly print the number of elements of the part, then print all the elements of the part in arbitrary order. There must be exactly p parts with even sum, each of the remaining k - p parts must have odd sum.

As there can be multiple partitions, you are allowed to print any valid partition.

Sample test(s)
input
5 5 3
2 6 10 5 9
output
YES
1 9
1 5
1 10
1 6
1 2
input
5 5 3
7 14 2 9 5
output
NO
input
5 3 1
1 2 3 7 5
output
YES
3 5 1 3
1 7
1 2
#include<bits/stdc++.h>
using namespace std;
int n , k , p ;
vector<int> o , e ;
int op , ep ;
int m ; int main () {
cin >> n >> k >> p ;
p = k-p ;
for (int i = 0 ; i < n ; i ++) {
int x ;
cin >> x ;
if (x & 1) o.push_back (x) ;
else e.push_back (x) ;
}
n = o.size () ; m = e.size () ;
if (n < p || n-p & 1 || (n-p)/2+m < k-p) {
puts ("NO") ;
return 0 ;
}
puts ("YES") ;
op = 0 , ep = 0 ;
for (; op < p-1 ;) printf ("1 %d\n" , o[op++]) ;
for (int i = 0 ; i < k-p-1 ; i ++) {
if (ep < m) printf ("1 %d\n" , e[ep++]) ;
else printf ("2 %d %d\n" , o[op++] , o[op++]) ;
}
if (p && k-p) printf ("1 %d\n" , o[op++]) ;
printf ("%d " , n-op + m-ep) ;
while (op < n) printf ("%d " , o[op++]) ;
while (ep < m) printf ("%d " , e[ep++]) ; puts ("") ;
return 0 ;
}

  这个构造题,跟14年牡丹江的一道题的构造思路有些相似的地方。

为了防止复杂化思路,你在进行的每一步操作都应该尽可能 -----符合题设的条件

并不使问题进一步复杂化。

这道题还需要的一个技巧是,因为要把所有的元素输出,所以用了两个变量op,ep来控制长度。

cf251.2.C (构造题的技巧)的更多相关文章

  1. hdu4671 Backup Plan ——构造题

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostrea ...

  2. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  3. Codeforces 482 - Diverse Permutation 构造题

    这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ....... ...

  4. BZOJ 3097: Hash Killer I【构造题,思维题】

    3097: Hash Killer I Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 963  Solved: 36 ...

  5. CF1110E Magic Stones(构造题)

    这场CF怎么这么多构造题…… 题目链接:CF原网 洛谷 题目大意:给定两个长度为 $n$ 的序列 $c$ 和 $t$.每次我们可以对 $c_i(2\le i<n)$ 进行一次操作,也就是把 $c ...

  6. CDOJ 1288 旅游的Final柱 构造题

    旅游的Final柱 题目连接: http://acm.uestc.edu.cn/#/problem/show/1288 Description 柱神要去打Final啦~(≧▽≦)/~啦啦啦 柱神来到了 ...

  7. CodeForces 297C Splitting the Uniqueness (脑补构造题)

    题意 Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指 ...

  8. HDU 5355 Cake (WA后AC代码,具体解析,构造题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5355 题面: Cake Time Limit: 2000/1000 MS (Java/Others) ...

  9. 【构造题 贪心】cf1041E. Tree Reconstruction

    比赛时候还是太慢了……要是能做快点就能上分了 Monocarp has drawn a tree (an undirected connected acyclic graph) and then ha ...

随机推荐

  1. checking for tgetent()... configure: error: NOT FOUND!

    今天centos出现了下面的异常: checking for tgetent()... configure: error: NOT FOUND! You need to install a termi ...

  2. 【Alpha版本】 第九天 11.17

    一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 完成我要应聘的详情显示,解决头像不能显示的问题,完成了报名及取消操 ...

  3. ubuntu 设置hostname

    永久修改hostname: # sudo vim /etc/hostname # sudo vim /etc/hosts

  4. Win10 Theano Install Guide

    basic install guide 1. download miniconda 2. conda install libpython mingw 3. conda install theano n ...

  5. 深度剖析Linux与Windows系统的区别,新手必读!

    当我们每个人接触Linux之前,应该先接触的都是windows吧?但我们一般接触Linux后,习惯linux的管理和使用方法后,我们再回过头再来使用windows的时候,内心其实是拒绝的.我们会觉得图 ...

  6. 通过rsync搭建一个远程备份系统(二)

    Rsync+inotify实时备份数据 rsync在同步数据的时候,需要扫描所有文件后进行对比,然后进行差量传输,如果文件达到了百万或者千万级别以上是,扫描文件的时间也很长,而如果只有少量的文件变更了 ...

  7. chown -R命令的使用

    chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷贝 ...

  8. Navicat 的使用(一)

    1.创建连接 主机名 : 可以不写名称随意 主机名/IP地址:localhost或者127.0.0.1 都是本机的意思 端口:默认3306   尽量不要改怕与其余端口重复,如有重名端口系统会报错 用户 ...

  9. ASP------<input type="file"/>上传文件

    界面代码(注意:runat="Server"和input file中name一定要有) <html xmlns="http://www.w3.org/1999/xh ...

  10. 自然语言22_Wordnet with NLTK

    QQ:231469242 欢迎喜欢nltk朋友交流 https://www.pythonprogramming.net/wordnet-nltk-tutorial/?completed=/nltk-c ...