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. (转)Elasticsearch查询规则------match和term

    es种有两种查询模式,一种是像传递URL参数一样去传递查询语句,被称为简单搜索或查询字符串(query string)搜索,比如 GET /megacorp/employee/_search //查询 ...

  2. Hardwood Species(stl map)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=203#problem/B 属于暴力 #include <stdio.h&g ...

  3. 谷歌浏览器:audio如何隐藏下载按钮

    当我们使用原生的audio标签时,可以看到如下的效果. 那么如何让下载按钮隐藏掉呢? 1. controlsList="nodownload" // 这个方法只支持 Chrome ...

  4. Postman使用js获取日期

    在用postman进行接口自动化测试的时候,某个查询接口需要使用到日期参数进行请求: 假设当前日期为2018-05-07 10:30:20 ,需要传的日期为: beginTime:2018-05-01 ...

  5. 7.5 Models -- Persisting Records

    一.概述 1. 在Ember Data上以每个实例为基础,records被持久化.在DS.Model的任何一个实例上调用save()并且它将产生一个网络请求. 2. 下面是一些例子: var post ...

  6. http协议基础(三)几种数据传输方式

    说说http协议的一些特点: 1)无状态 http协议是一种自身不对请求和响应之间的通信状态进行保存的协议,即无状态协议. 这种设置的好处是:更快的处理更多的请求事务,确保协议的可伸缩性 不过随着we ...

  7. mysql的Navicat查看数据库的ER图

    1.mysql数据库表间的关系图可以通过navicat查看.

  8. 原生http模块与使用express框架对比

    node的http创建服务与利用Express框架有何不同 原生http模块与使用express框架对比: const http = require("http"); let se ...

  9. 54. Spiral Matrix(剑指offer--19)

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  10. 80. Remove Duplicates from Sorted Array II(双指针)

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...