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<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 1000000007
#define inf 999999999
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int even[],ji;
int odd[],ou;
int main()
{
int x,y,z,i,t;
int n,k,p;
scanf("%d%d%d",&n,&k,&p);
for(i=;i<n;i++)
{
scanf("%d",&z);
if(z&)
even[ji++]=z;
else
odd[ou++]=z;
}
if(ji<k-p||(ji-k+p)&)
{
printf("NO\n");
return ;
}
else
{
if(ou+(ji-k+p)/<p)
{
printf("NO\n");
return ;
}
else
{
printf("YES\n");
if(p==)
{
for(i=;i<k-p-;i++)
printf("1 %d\n",even[i]);
printf("%d",ji-k++ou);
for(i=k-p-;i<ji;i++)
printf(" %d",even[i]);
for(i=;i<ou;i++)
printf(" %d",odd[i]);
printf("\n");
}
else if(ou<p)
{
int fuck=k-p;
for(i=;i<k-p;i++)
printf("1 %d\n",even[i]);
for(i=;i<ou;i++)
printf("1 %d\n",odd[i]);
for(i=;i<p-ou-;i++)
printf("2 %d %d\n",even[fuck++],even[fuck++]);
printf("%d",ji-fuck);
for(i=fuck;i<ji;i++)
printf(" %d",even[i]);
printf("\n");
}
else
{
for(i=;i<k-p;i++)
printf("1 %d\n",even[i]);
for(i=;i<p-;i++)
printf("1 %d\n",odd[i]);
printf("%d",n-k+);
for(i=k-p;i<ji;i++)
printf(" %d",even[i]);
for(i=p-;i<ou;i++)
printf(" %d",odd[i]);
printf("\n");
}
}
}
return ;
}

codeforces 251 div2 C. Devu and Partitioning of the Array 模拟的更多相关文章

  1. Codeforces 439C Devu and Partitioning of the Array(模拟)

    题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数 ...

  2. codeforces 251 div2 D. Devu and his Brother 三分

    D. Devu and his Brother time limit per test 1 second memory limit per test 256 megabytes input stand ...

  3. CodeForce 439C Devu and Partitioning of the Array(模拟)

     Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes ...

  4. CF 439C Devu and Partitioning of the Array

    题目链接: 传送门 Devu and Partitioning of the Array time limit per test:1 second     memory limit per test: ...

  5. CF 439C(251C题)Devu and Partitioning of the Array

    Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes ...

  6. Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array

    注意p的边界情况,p为0,或者 p为k 奇数+偶数 = 奇数 奇数+奇数 = 偶数 #include <iostream> #include <vector> #include ...

  7. codeforces 439D Devu and Partitioning of the Array(有深度的模拟)

    题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...

  8. codeforces 439C Devu and Partitioning of the Array(烦死人的多情况的模拟)

    题目 //这是一道有n多情况的烦死人的让我错了n遍的模拟题 #include<iostream> #include<algorithm> #include<stdio.h ...

  9. codeforces C. Devu and Partitioning of the Array

    题意:给你n个数,然后分成k部分,每一个部分的和为偶数的有p个,奇数的有k-p个,如果可以划分,输出其中的一种,不可以输出NO; 思路:先输出k-p-1个奇数,再输出p-1个偶数,剩余的在进行构造.  ...

随机推荐

  1. qsv转换为mp4

    1:下载  装换工具:http://www.downza.cn/soft/27484.html 2:双击打开exe可执行程序. 3:添加要转换的文件,和转换后要存储的位置 4:开始转换,转换为flv格 ...

  2. 训练/验证/测试集设置;偏差/方差;high bias/variance;正则化;为什么正则化可以减小过拟合

    1. 训练.验证.测试集 对于一个需要解决的问题的样本数据,在建立模型的过程中,我们会将问题的data划分为以下几个部分: 训练集(train set):用训练集对算法或模型进行训练过程: 验证集(d ...

  3. C# 定时器 一个简单 并且可以直接运行的Demo

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  4. EPD的驱动

    整个e-ink技术的生产流程:1997年从MIT媒体实验室走出来的E-INK公司成立并专注于研发具有良好阅读体验的电子纸.其中最著名的产品就是Vizplex 电子墨水.E-INK提供电子墨水给Pane ...

  5. python服务器端、客户端的模型,客服端发送请求,服务端进行响应(web.py)

    服务器端.客户端的模型,客服端发送的请求,服务端的响应 相当于启动了一个web server install web.py 接口框架用到的包 http://webpy.org/tutorial3.zh ...

  6. SQL语句调优汇总

    1.插入数据的表或临时表,预先创建好表结构,能够加快执行速度 2.where 条件判断的字段以及连接查询的条件字段   都添加上索引   能够加快执行速度 3.尽量避免使用 like ,类似 like ...

  7. MySQL Crash Course #12# Chapter 18. Full-Text Searching

    INDEX 由于性能.智能结果等多方面原因,在搜索文本时,全文搜索一般要优于通配符和正则表达式,前者为指定列建立索引,以便快速找到对应行,并且将结果集智能排序.启用查询扩展可以让我们得到未必包含关键字 ...

  8. Android JSON 解析关键代码

    Android Json 解析其实还是蛮重要的知识点,为什么这么说呢,因为安卓通信大部分的协议都是使用 json 的方式传输,我知道以前大部分是使用的 xml ,但是时代在发展社会在进步,json 成 ...

  9. MS08_067漏洞测试——20145301

    MS08_067漏洞测试 实验步骤 search MS08_067查看相关信息 show payloads命令查找需要的攻击载荷 选择generic/shell_reverse_tcp来获取漏洞主机的 ...

  10. 20165310 Java实验四 《Android程序设计》

    20165310 实验四 <Android程序设计> 第24章:初识Android 任务一:改写res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号 首 ...