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文章随机调用等一些常用标签

    1.帝国CMS文章随机调用等一些常用标签 [e:loop={'news',10,18,0,'newstime>UNIX_TIMESTAMP()-86400*7','onclick desc'}] ...

  2. 在Ubuntu上如何往fcitx里添加输入法

    Ubuntu 16.04引入了一个新的包管理工具apt, 用法与apt-get类似. 在终端用apt搜索fcitx支持的输入法 apt search fcitx All Fcitx related p ...

  3. JavaScript之闭包

    JavaScript之闭包 在JavaScript中,闭包恐怕是很多人不能理解的一个概念了,甚至很多人也会把闭包和匿名函数混淆. 闭包是有权访问另一个函数作用域中的变量的函数.首先要明白的就是,闭包是 ...

  4. chmod 和 chown 的用法

    一.chown 命令 用途:更改文件的所有者或组.命令由单词change owner组合而成. 使用示例: 1,更改文件的所有者: chown jim program.c 文件 program.c 的 ...

  5. .net4.0及Silverlight_Tools for vs2008sp1安装失败解决办法

    安装.net framework 4.0失败,出现HRESULT 0xc8000222错误代码 1.开始-运行-输入cmd,运行命令     net stop WuAuServ 2.开始-运行-输入  ...

  6. Java——下拉列表框:JComboBox

    import java.awt.Container; import java.awt.GridLayout; import java.awt.event.WindowAdapter; import j ...

  7. Nginx:Pitfalls and Common Mistakes

    New and old users alike can run into a pitfall. Below we outline issues that we see frequently as we ...

  8. Java Web学习笔记-Servle生命周期

    Servlet会在服务器启动或第一次请求该Servlet的时候开始生命周期,在服务器停止的时候结束生命周期. 无论请求多少次Servlet,最多只有一个Servlet实例.多个客户端并发请求Servl ...

  9. 入门:PHP:hello world!

    <?php echo 'hello'."\n"." world!"."good night!";//2016.09.18 22:57? ...

  10. LaTeX 页眉页脚的设置

    Latex中页眉页脚的设置 1. 首先要加页眉页脚的话,需要启动宏: 我通常用fancyhdr宏包来设置页眉和页脚. \usepackage{fancyhdr} 我们在 LaTeX 中先把 page ...