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. 帝国cms搜索表单用法

    还有一些没有测试,用到了再补充. <form action="[!--news.url--]e/search/index.php" method="post&quo ...

  2. CF 701B Cells Not Under Attack(想法题)

    题目链接: 传送门 Cells Not Under Attack time limit per test:2 second     memory limit per test:256 megabyte ...

  3. 如何判断ios设备中是否安装了某款应用

    URL Schemes关键字研究一下即可 常见得URL Schemes见http://www.cnblogs.com/huangzs/p/4491286.html if ([[UIApplicatio ...

  4. java学习总结

    1 获得项目绝对路径 String path = request.getContextPath(); String basePath = request.getScheme() + ":// ...

  5. Untiy3D - 窗口界面2

    Component 组件 Mesh:网格 Mesh Filter: 网格滤镜 Mesh Renderer 网格渲染器 Mesh Collider: 网格碰撞器.网格碰撞节点 Convex: 凸的.凸面 ...

  6. 【原】React操作表单

    最近的项目中开发中都是用react,其中有用到react去操纵表单.然后自己就在每个表单元素中添加 ref,  然后再像jquery操作dom一样去操纵这个ref, 代码如下: 首先我在每个表单元素那 ...

  7. 注释(Annotation)

    J2SE 5.0提供了很多新的特征.其中一个很重要的特征就是对元数据(Metadata)的支持.在J2SE 5.0中,这种元数据称为注释(Annotation).通过使用注释,程序开发人员可以在不改变 ...

  8. Java学习笔记2

    package welcome; public class Constants { public static void main(String[] args){ final double CM_PE ...

  9. ecshop团购显示“库存不足”

    产生原因:是因为产品设置了多属性 解决办法:打开group_buy.php 第 267行找到 empty($product_info) ? $product_info = array(, ) : '' ...

  10. Fork函数初识

    fork函数用于创建子进程,典型的调用一次,返回两次的函数.其中调用进程返回子进程的PID,而子进程则返回0.但是两个进程的执行顺序是不定的. fork函数调用完成以后父进程的虚拟存储空间被拷贝给了子 ...