CodeForce 439C Devu and Partitioning of the Array(模拟)
1 second
256 megabytes
standard input
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.
The first line will contain three space separated integers n, k, p (1 ≤ k ≤ n ≤ 105; 0 ≤ p ≤ k).
The next line will contain n space-separated distinct integers representing the content of array a: a1, a2, ..., an (1 ≤ ai ≤ 109).
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.
5 5 3
2 6 10 5 9
YES
1 9
1 5
1 10
1 6
1 2
5 5 3
7 14 2 9 5
NO
5 3 1
1 2 3 7 5
YES
3 5 1 3
1 7
1 2
#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(模拟)的更多相关文章
- Codeforces 439C Devu and Partitioning of the Array(模拟)
题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数 ...
- CF 439C Devu and Partitioning of the Array
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:1 second memory limit per test: ...
- 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 ...
- codeforces 439C Devu and Partitioning of the Array(烦死人的多情况的模拟)
题目 //这是一道有n多情况的烦死人的让我错了n遍的模拟题 #include<iostream> #include<algorithm> #include<stdio.h ...
- 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 ...
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
注意p的边界情况,p为0,或者 p为k 奇数+偶数 = 奇数 奇数+奇数 = 偶数 #include <iostream> #include <vector> #include ...
- codeforces 439D Devu and Partitioning of the Array(有深度的模拟)
题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...
- codeforces C. Devu and Partitioning of the Array
题意:给你n个数,然后分成k部分,每一个部分的和为偶数的有p个,奇数的有k-p个,如果可以划分,输出其中的一种,不可以输出NO; 思路:先输出k-p-1个奇数,再输出p-1个偶数,剩余的在进行构造. ...
- 【Henu ACM Round#20 D】 Devu and Partitioning of the Array
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一开始所有的数字单独成一个集合. 然后用v[0]和v[1]记录集合的和为偶数和奇数的集合它们的根节点(并查集 然后先让v[0]的大小 ...
随机推荐
- 第一篇:GCD的使用
一.主队列介绍 主队列是和主线程相关的队列,主队列是GCD自带的一种特殊的串行队列,放在主队列中的任务,都会放到主线程中执行. 提示:如果把任务放到主队列进行处理,那么不论处理函数是异步的还是同步的都 ...
- winform控件记录
winform: --------------------------------------------------- Button控件: 属性: BackColor: 背景颜色 Backgroun ...
- WebLech是一个功能强大的Web站点下载与镜像工具
WebLech是一个功能强大的Web站点下载与镜像工具.它支持按功能需求来下载web站点并能够尽可能模仿标准Web浏览器的行为.WebLech有一个功能控制台并采用多线程操作. http://sour ...
- 解决TCP网络传输“粘包”问题
当前在网络传输应用中,广泛采用的是TCP/IP通信协议及其标准的socket应用开发编程接口(API).TCP/IP传输层有两个并列的协议:TCP和UDP.其中TCP(transport contro ...
- 安装虚拟机时出现The Microsoft Runtime DLL
参考文档: http://zhidao.baidu.com/link?url=1E4vr6ToPGm_kAZw4voOqzrPtzGaSIqy3kvcGXehs3KJAkirNKOHJbrsxec3f ...
- 以xml的方式实现动画
1.java代码 package com.example.tweenanim; import android.os.Bundle; import android.app.Activity; impor ...
- pop,墨刀,快现、justinmind 、Axure
原型设计软件 墨刀:https://modao.cc Justinmind: http://www.zhihu.com/question/26662368/answer/33586218 http:/ ...
- 基于端口的VLAN典型配置指导
本文为转发,简单明了,我喜欢 VLAN典型配置全过程如下: 组网图 图1-1 基于端口的VLAN组网示意图 应用要求 如图1-1所示,Switch A和Switch B分别连接了不同部门使用的Host ...
- log4cpp的初步使用
(1)下载log4cpp的工程,编译生成lib文件和dll库 下载路径为:http://sourceforge.net/projects/log4cpp/files/latest/download 如 ...
- ELK 之一:ElasticSearch 基础和集群搭建
一:需求及基础: 场景: 1.开发人员不能登录线上服务器查看详细日志 2.各个系统都有日志,日志数据分散难以查找 3.日志数据量大,查询速度慢,或者数据不够实时 4.一个调用会涉及到多个系统,难以在这 ...