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中文字斜着显示

    /** * 自定义一个Textview * * @author Administrator * */ public class MyTextView extends TextView { public ...

  2. cocos2d-x学习日志(18) --程序是怎样開始执行与结束?

    问题的由来 怎么样使用 Cocos2d-x 高速开发游戏.方法非常easy,你能够看看其自带的例程,或者从网上搜索教程,执行起第一个HelloWorld,然后在 HelloWorld 里面写相关逻辑代 ...

  3. Linux下IP等网络配置

    Linux下IP等网络配置: 我所知道一共三种方式,下面简单介绍(注意:网络配置必须”root管理员“登录才能进行配置). 一 1.首先在命令行输入[ifconfig]命令,可看到相关网络信息,其中” ...

  4. 转:: 刺鸟:用python来开发webgame服务端(1)

    来源:http://ciniao.me/article.php?id=9 --------------- 刺鸟原创文章,转载请注明出处    在开始之前,先简单描述一下项目的特点:我要实现的是一个mm ...

  5. python中json操作

    1.写操作.json文件dumps().dump()函数 d = { 'zll': { 'addr': '北京', 'age': 28 }, 'ljj': { 'addr': '北京', 'age': ...

  6. mysql导出csv文件

    SELECT * FROM (select 'id','url','大分类','分类','贴吧名称','关注用户数','帖子数量','简介','帖子名称','楼主ID','发表时间','采集时间',' ...

  7. Spring整合Velocity模版引擎

    1. 首先通过pom.xml自动加载velocity扩展包到工程: <dependency> <groupId>velocity</groupId> <art ...

  8. (转)IOS崩溃 异常处理(NSSetUncaughtExceptionHandler)

    iOS已发布应用中对异常信息捕获和处理 代码下载地址:http://download.csdn.net/detail/daiyelang/6740205 iOS开发中我们会遇到程序抛出异常退出的情况, ...

  9. JavaWeb 之监听器

    1. JavaWeb 监听器概述 在 JavaWeb 被监听的事件源为: ServletContext, HttpSession, ServletRequest, 即三大域对象. 监听域对象" ...

  10. vb.net 正則表達式 取 固定格式的字符

    vb.net 正則表達式 取 固定格式的字符: 原始字符串:strSqlTmp="select * from A_TEST where a_data = '@1@' and b_link = ...