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

题意:给出n个数。要分成k份。每份有若干个数。可是仅仅须要关注该份的和为奇数还是偶数,要求偶数堆的个数为p。输出方案。

分析:先输出k-p-1组奇数,然后输出p-1组偶数;假设 p!=0&&(k-p)!=0,再输出一个奇数,这时奇数的已经构造完毕。最后把剩下的所有输出为一组就可以。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int MAXN = 1e5 + 100;
int a[MAXN], b[MAXN];
int main()
{
int n, p, k, i, odd = 0, even = 0, c;
scanf("%d%d%d",&n,&k,&p);
for(i = 0; i < n; i++)
{
scanf("%d",&c);
if(c&1)
a[odd++] = c;
else
b[even++] = c;
}
if(odd < k-p || (odd - k + p) % 2 == 1 || even + (odd - k + p) / 2 < p)
printf("NO\n");
else
{
printf("YES\n");
int tmp = k - p;
for(i = 0; i < tmp - 1; i++)
printf("1 %d\n",a[--odd]);
for(i = 0; i < p - 1; i++)
{
if(even)
printf("1 %d\n", b[--even]);
else
{
printf("2 %d %d\n", a[odd-1], a[odd-2]);
odd -= 2;
}
}
if(tmp && p)
printf("1 %d\n", a[--odd]);
printf("%d", odd+even);
while(odd)
printf(" %d",a[--odd]);
while(even)
printf(" %d\n", b[--even]);
printf("\n");
}
return 0;
}

CodeForce 439C 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. CF 439C Devu and Partitioning of the Array

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

  3. codeforces 251 div2 C. Devu and Partitioning of the Array 模拟

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

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

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

  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 C. Devu and Partitioning of the Array

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

  9. 【Henu ACM Round#20 D】 Devu and Partitioning of the Array

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一开始所有的数字单独成一个集合. 然后用v[0]和v[1]记录集合的和为偶数和奇数的集合它们的根节点(并查集 然后先让v[0]的大小 ...

随机推荐

  1. 【Maven】项目添加Maven类库依赖

    1.右击项目-->Maven-->EnableDependencyManagement,按步骤完成操作. 2.右击项目-->Properties-->DeploymentAss ...

  2. iOS 拍照保存到相册

    之前看了一些开源的代码,里面有一个功能,就是将图片下载到相册,仔细看了其中的代码,只有很简单的一句话,并且保存过后,还可以判断是否保存成功. 如下代码所示, 点击按钮,将self.imageView上 ...

  3. MAC安裝《Genymotion Android模擬器》大玩Android APP (神魔之塔)

    链接地址:http://www.minwt.com/mac/10083.html/comment-page-2 MAC» 智慧型裝罝» Android | 2014/02/12 Android是一個開 ...

  4. HDU 3068 最长回文 【最长回文子串】

    和上一题一样,不过这题只是要求最长回文子串的长度 在此采用了非常好用的Manacher算法 据说还是O(n) 的效率QAQ 详细用法参考了上篇博客的参考资料,这两天有空学习一下~ Source cod ...

  5. mvc导航配置(View页面)

    @using Seyoit.Website.Config@using Seyoit.Website.Config.Navigation@{ var action = ViewContext.Route ...

  6. android项目中刷新activity界面

    android项目中在sqlite数据库插入/更新/删除数据后: 1. 刷新当前activity界面数据(手动刷新): 在activity类下新增一个refresh()方法: /** * 刷新, 这样 ...

  7. Verilog之case语句

    verilog设计进阶 时间:2014年5月6日星期二 主要收获: 1.学会使用case语句: 2.学会使用随机函数$random. $random: 1.函数说明:$random函数调用时返回一个3 ...

  8. 【转】windows 7系统安装与配置Tomcat服务器环境

    原文链接: windows 7系统安装与配置Tomcat服务器环境 工具/原料 jdk-8u51-windows-x64(我的系统是64位系统,32位的请选x86下载)下载地址:http://www. ...

  9. (step8.2.6)hdu 1848(Fibonacci again and again——组合博弈)

    题目大意:输入3个整数m,n,p,分别表示3堆石头中的石头个数 解题思路: 1)斐波那契数列的第16个数fib[16] == 1597 2)(sg[m]^sg[n]^sg[p])   .一定要加括号, ...

  10. 高级特性(7)- 高级AWT

    7.1 绘图操作流程7.2 形状7.3 区域7.4 笔划7.5 着色7.6 坐标变换7.7 剪切7.8 透明与组合7.9 绘图提示7.10 图像的读取器和写入器 7.10.1 获得图像文件类型的读取器 ...