博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF 439C(251C题)Devu and Partitioning of the Array
阅读量:6985 次
发布时间:2019-06-27

本文共 2577 字,大约阅读时间需要 8 分钟。

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 intok disjoint non-empty parts such thatp of the parts have even sum (each of them must have even sum) and remainingk -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 n, k, p (1 ≤ k ≤ n ≤ 105; 0 ≤ p ≤ k). The next line will containn space-separated distinct integers representing the content of arraya: a1, 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. Theith of them should contain the content of theith 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 exactlyp parts with even sum, each of the remainingk -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 32 6 10 5 9
Output
YES1 91 51 101 61 2
Input
5 5 37 14 2 9 5
Output
NO
Input
5 3 11 2 3 7 5
Output
YES3 5 1 31 71 2

题目大意:一组数组分成k部分,p组和为偶数的部分,k-p组和为奇数的部分。可以输出YES。否则输出NO

第3组的案例来讲,

1, 2 是偶的,

剩余的

3 。5 1 3

1, 7

和是奇的

推断不难,主要是记录奇数的个数odd,假设odd>=k-p(须要的奇数组)而且剩余的奇数个数是偶数个(以配套凑成和为偶数的组合),同一时候偶数的个数even  +(剩余奇数可以凑成的最多的和为偶数的组合)>=p(即须要的偶数组);

所以一个条件语句就能控制

if(odd>=(k-p)&&(odd-(k-p))%2==0&&(even+(odd-(k-p))/2)>=p)
题目难处在于,后面的组合分配,在代码中具体解释。

AC代码例如以下:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define ll long long#define M 100005struct H{ int x,y;//x为值。y为奇偶标记}a[M];int cmp(H q,H w){ return q.y
>n>>k>>p; for(i=0;i
>a[i].x; if(a[i].x%2==0) {a[i].y=2;even++;}//标记偶数为2。统计偶数个数 else {a[i].y=1;odd++;}//标记奇数为1,统计奇数个数 } sort(a,a+n,cmp);//通过对标记值的排序,将数组奇数前置 if(odd>=(k-p)&&(odd-(k-p))%2==0&&(even+(odd-(k-p))/2)>=p) { cout<<"YES"<
k-p&&i

转载地址:http://ixmpl.baihongyu.com/

你可能感兴趣的文章
增强 wp_list_authors 显示文章最多的作者
查看>>
代码:显示查询的日历
查看>>
完整的目标管理三段俱全
查看>>
AD 脚本kixtart运用之六(outlook邮件批量生成签名)
查看>>
优化SQL查询:如何写出高性能SQL语句
查看>>
简单易用的库存管理软件、进销存软件
查看>>
docker WARNING: IPv4 forwarding is disabled. 解决方法
查看>>
Tomcat+Nginx+Memcached集群部署
查看>>
通过FFMPEG代码学习函数指针和指针函数
查看>>
puppet 基础篇
查看>>
到底怎么样才叫看书?
查看>>
python 将ipv4的格式转换
查看>>
C语言宏的副作用的简单实例
查看>>
关于C语言结构体对齐的学习
查看>>
富文本框
查看>>
windows下安装rabbitMQ
查看>>
20个优秀的移动(iPhone)网站设计案例
查看>>
CentOS 6.3安装Nginx开启目录浏览、下载功能
查看>>
oracle登陆认证方式
查看>>
FMDB/SQLCipher数据库管理
查看>>