题意:给你n个数,然后分成k部分,每一个部分的和为偶数的有p个,奇数的有k-p个,如果可以划分,输出其中的一种,不可以输出NO;

思路:先输出k-p-1个奇数,再输出p-1个偶数,剩余的在进行构造。  奇数+奇数=偶数。

 #include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#define maxn 1000100
#define ll long long
using namespace std; int n,k,p;
ll a[maxn];
vector<int>qq;
vector<int>pp; int main()
{
scanf("%d%d%d",&n,&k,&p);
for(int i=; i<=n; i++)
{
scanf("%lld",&a[i]);
if(a[i]%==) qq.push_back(a[i]);
else if(a[i]%!=) pp.push_back(a[i]);
}
int odd=pp.size();
int even=qq.size();
if(odd<k-p||(odd>=k-p&&even+(odd-(k-p))/<p)||(odd-(k-p))%==)
printf("NO\n");
else
{
printf("YES\n");
for(int i=; i<k-p-; i++)
{
printf("%d %d\n",,pp[i]);
}
int x=k-p-;
int y=even;
if(x<)x=;
for(int i=; i<p-; i++)
{
if(y)
{
printf("%d %d\n",,qq[y-]);
y--;
}
else
{
printf("%d %d %d\n",,pp[x],pp[x+]);
x+=;
}
}
if(k-p!=&&p)
{
printf("%d %d\n",,pp[x]);
x++;
}
if(x<) x=;
printf("%d ",y+odd-x);
while(y)
{
printf("%d ",qq[y-]);
y--;
}
while(x<odd)
{
printf("%d ",pp[x]);
x++;
}
printf("\n");
}
return ;
}

codeforces 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 439D Devu and Partitioning of the Array(有深度的模拟)

    题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...

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

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

  4. 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 ...

  5. 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 ...

  6. CF 439C Devu and Partitioning of the Array

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

  7. 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 ...

  8. Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array

    注意p的边界情况,p为0,或者 p为k 奇数+偶数 = 奇数 奇数+奇数 = 偶数 #include <iostream> #include <vector> #include ...

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

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

随机推荐

  1. richTextBox1 转到行号

      private void button2_Click(object sender, EventArgs e) {     Win32CommonDialog.frm_GOTO frm = new  ...

  2. JavaCodeTra 猴子选猴王 约瑟夫循环

    之前用的是循环链表,java刚学,不知道怎么用链表.用个小算法吧 代码: import java.util.Scanner; /** * */ /** * @author john * @约瑟夫循环/ ...

  3. 利用systemtap学习Linux路由代码

    http://bbs.chinaunix.net/thread-4090162-1-1.html 一.为什么要这样做读kernel route子系统代码,当我弄懂了数据结构之间的关系以及控制流程后,心 ...

  4. Windows7如何在安全模式下卸载驱动(亲测)

    在桌面“我的电脑”上点鼠标右键,选择“属性”,“硬件”,“设备管理器”,找到“显示卡选项”,打开前面的“+”,然后按鼠标右键,选择“卸载”就可以了. (亲测,主板驱动卸载成功启动)

  5. Swift: Initialization-1

    初始化的过程包括为每一个存储属性设置一个初始值和其他步骤.通过定义构造函数来实现初始化的过程,跟oc的初始化函数不同,Swift的构造函数不返回一个值.它们的主要角色是确保一个类型的实例在初次使用前被 ...

  6. APP切图那些事儿-Android ios

  7. Oracler读取各种格式的相关日期格式

    CREATE OR REPLACE Package Pkg_Stm_Date As     --Purpose:相关日期处理功能包          --获取某一天是第几周     Function ...

  8. jad批量反编译class和jadeclipse集成到eclipse的设置方法

    安装jad配置 1.从http://varaneckas.com/jad/下载windows版本的jad.exe 2.安装完毕后配置jad的系统环境变量 批量解压jar和class文件 1.使用7zi ...

  9. dede 最近一天发布的文章标题前加hot

    {dede:list pagesize ='15'} <!-- 模板1 --> <div class="news_list tp_a setp1"> < ...

  10. 给Sublime Text2安装轻量级代码提示插件:SublimeCodeIntel

    步骤: 1.下载SublimeCodeIntel(地址https://github.com/SublimeCodeIntel/SublimeCodeIntel): 2.将下载的压缩包解压,并放置在Pa ...