博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 251 div2 C. Devu and Partitioning of the Array 模拟
阅读量:4596 次
发布时间:2019-06-09

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

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.

Examples
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

 题意:给你n个数,分成m堆,这些堆的和为偶数的堆为p堆;

思路:分析清楚情况就是,偶数永远是偶数,但是两个奇数可以组成一个偶数;

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define ll __int64#define mod 1000000007#define inf 999999999//#pragma comment(linker, "/STACK:102400000,102400000")int scan(){ int res = 0 , ch ; while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) ) { if( ch == EOF ) return 1 << 30 ; } res = ch - '0' ; while( ( ch = getchar() ) >= '0' && ch <= '9' ) res = res * 10 + ( ch - '0' ) ; return res ;}int even[100010],ji;int odd[100010],ou;int main(){ int x,y,z,i,t; int n,k,p; scanf("%d%d%d",&n,&k,&p); for(i=0;i

 

转载于:https://www.cnblogs.com/jhz033/p/5475078.html

你可能感兴趣的文章
Spring学习总结五——SpringIOC容器五
查看>>
解决多个ajax页面请求,页面loading阻塞问题
查看>>
Executor
查看>>
Javascript 表单验证对象控件 + ajax简单验证重复项与ajax提交数据
查看>>
使用抽象工厂设计一个简单的交易模块
查看>>
如何将广告始终定位到网页右下角
查看>>
常用js整理
查看>>
查看oracle/mysql数据库版本号
查看>>
memset函数
查看>>
使用postman+newman+python做接口自动化测试
查看>>
实体框架继承关系。很好
查看>>
201671010110 2016 2017 2《java程序设计》
查看>>
flask的基础认识
查看>>
静态blog的免费托管部署、加域名与搜索优化(SEO)
查看>>
oracle trunc(d1[,c1])
查看>>
linux 内核定时器的实现
查看>>
Android和IOS等效MD5加密
查看>>
小房间灯.20190512
查看>>
绘图-路径
查看>>
恢复sudo的权限的命令
查看>>