http://codeforces.com/problemset/problem/439/C

题意:给你n个数,分成k个非空集合,其中有p个集合的元素和为偶数,其余k-p个集合的元素和为奇数。

思路:考虑两个数和的情况,奇+奇=偶,奇+偶=奇,偶+偶=偶。所以解决方案不存在的情况为

(oddnum<k-p || (oddnum-(k-p))%2!=0 || evennum+(oddnum-(k-p))/2<p)。

先输出k-p-1组的单个奇数,输出p-1组偶数(先为单个偶数,偶数不够两个奇数),若(k!=0&&k-p!=0),输出一个奇数,其余数一组输出。

#include<cstdio>
#include<iostream>
using namespace std;
int even[],odd[];
int main() {
int n,k,p,evennum=,oddnum=;
int dig;
scanf("%d%d%d",&n,&k,&p);
for(int i=;i<n;i++) {
scanf("%d",&dig);
if(dig%==) even[evennum++]=dig;
else odd[oddnum++]=dig;
}
if(oddnum<k-p || (oddnum-(k-p))%!=) printf("NO\n");
else {
if((evennum+(oddnum-(k-p))/)<p) printf("NO\n");
else {
int e=evennum,o=oddnum;
printf("YES\n");
int a;
for(a=;a<k-p-;a++) {
printf("1 %d\n",odd[a]);o--;
}
int j=a;
for(int i=;i<p-;i++) {
if(e>) {
printf("1 %d\n",even[i]);
e--;
}
else {
printf("2 %d %d\n",odd[j++],odd[j++]);
o-=;
}
}
if(p!=&&k-p!=) {
printf("1 %d\n",odd[j]);o--;
}
printf("%d ",o+e);
for(int i=evennum-e;i<evennum;i++) printf("%d ",even[i]);
for(int i=oddnum-o;i<oddnum;i++) printf("%d ",odd[i]);
printf("\n");
}
}
return ;
}

codeforces 439C 模拟的更多相关文章

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

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

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

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

  3. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  4. CodeForces - 404B(模拟题)

    Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

  5. Codeforces 709B 模拟

    B. Checkpoints time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  6. CodeForces - 404A(模拟题)

    Valera and X Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit ...

  7. Codeforces 390A( 模拟题)

    Inna and Alarm Clock Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64 ...

  8. Codeforces 452D [模拟][贪心]

    题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...

  9. CodeForces - 796B 模拟

    思路:模拟移动即可,如果球落入洞中停止移动.注意:有可能第一个位置就是洞!! AC代码 #include <cstdio> #include <cmath> #include ...

随机推荐

  1. android中TabHost和RadioGroup

    android底部菜单应用 博客分类: android--UI示例 TabHostMenuRadioGroupButton  在android中实现菜单功能有多种方法. Options Menu:用户 ...

  2. lucene学习-创建索引

    本文的lucene是基于lucene3.5版本. 使用lucene实现搜索引擎开发,核心的部分是建立索引和搜索.本节主要是记录创建索引部分的内容. 创建的索引结构如图所示. 创建索引的步骤分为以下几个 ...

  3. 【转】 VC++ 关闭程序后任务管理器进程中进程仍然存在的解决方法

    转载出处:http://blog.csdn.net/zac_sian/article/details/50809084 可以从以下两个方面进行查找! 1.程序开启了进程,进程中使用了while(1), ...

  4. The server encountered an internal error that prevented it from fulfilling this request.(JsonMappingException: Conflicting getter definitions)

    在测试一个方法,dubug查看查询结果已经出来了,结果页面上是The server encountered an internal error that prevented it from fulfi ...

  5. nginx发布的nginScript

    nginx发布的nginScript 背景 2015年9月,nginx宣布支持类JavaScript语言.这意味着开发者可以更轻松.自由的控制全球最优秀的HTTP及反向代理服务器,并在此之上可以衍生出 ...

  6. ehcarts之toolbox,工具栏

    toolbox 工具栏.内置有导出图片,数据视图,动态类型切换,数据区域缩放,重置五个工具. feature各工具配置项.具体显示功能 1.saveAsImage 保存为图片. 2.restore 还 ...

  7. 通过less 计算 得出图片均分布局

    <style lang="less"> @import "../style/weui.wxss"; // WXSS · 小程序 https://de ...

  8. 使用QFuture类监控异步计算的结果

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Amnes1a/article/details/65630701在Qt中,为我们提供了好几种使用线程的 ...

  9. ThreadLocal (二):什么时候使用 InheritableThreadLocal

    一.ThreadLocal 在父子线程传递的问题 public class InheritableThreadLocalDemo { // 全局变量 // static ThreadLocal< ...

  10. (4.6)sql server索引缺失提示

    SQLSERVER如何查看索引缺失 sql server索引缺失提示 当大家发现数据库查询性能很慢的时候,大家都会想到加索引来优化数据库查询性能, 但是面对一个复杂的SQL语句,找到一个优化的索引组合 ...