题目链接:Codeforces 439C Devu and Partitioning of the Array

题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数,要求偶数堆的个数为p。

输出方案。

解题思路:首先先将数组依照奇偶排序。也能够分开储存。

然后先单独分k-p个奇数,然后后面的就将两个奇数当一个偶数分配。分配过程中计算是否满足,比方说奇数是否成对,以及是否分成了k堆。

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm> using namespace std;
const int N = 1e5 + 5; int n, k, p, d[N];
vector<int> g[N]; inline bool cmp (const int& a, const int& b) {
return (a&1) > (b&1);
} void init () {
scanf("%d%d%d", &n, &k, &p);
for (int i = 0; i < n; i++)
scanf("%d", &d[i]); sort(d, d + n, cmp);
for (int i = 0; i < k; i++)
g[i].clear();
} bool judge () {
int mv = 0;
for (int i = 0; i < k - p; i++) {
if (d[mv]&1)
g[i].push_back(d[mv++]);
else
return false;
} int t = k - p;
while (mv < n) { t %= k; if (d[mv]&1) {
g[t].push_back(d[mv++]); if ((d[mv]&1) != 1 || mv >= n)
return false; g[t].push_back(d[mv++]);
} else {
g[t].push_back(d[mv++]);
}
t++;
} if (g[k-1].size() == 0)
return false;
return true;
} int main () {
init(); if (judge()) {
printf("YES\n");
for (int i = 0; i < k; i++) {
printf("%lu", g[i].size());
for (int j = 0; j < g[i].size(); j++)
printf(" %d", g[i][j]);
printf("\n");
}
} else
printf("NO\n"); return 0;
}

Codeforces 439C Devu and Partitioning of the Array(模拟)的更多相关文章

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

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

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

  3. CF 439C Devu and Partitioning of the Array

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

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

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

  6. codeforces C. Devu and Partitioning of the Array

    题意:给你n个数,然后分成k部分,每一个部分的和为偶数的有p个,奇数的有k-p个,如果可以划分,输出其中的一种,不可以输出NO; 思路:先输出k-p-1个奇数,再输出p-1个偶数,剩余的在进行构造.  ...

  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. 《Effective C++ 》学习笔记——规定10

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  2. ftk学习记(消息框篇)

    [ 声明:版权全部,欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing @163.com] 上一篇说到了输入框.闲话不多说,首先看结果显示, 大家看看效果是不是和我们之前说的一样.今天, ...

  3. php文件操作基本使用方法

    <?php /* $fp=fopen("tmp.html","r"); $str=fread($fp,filesize("tmp.html&qu ...

  4. 谈论高并发(二十二)解决java.util.concurrent各种组件(四) 深入了解AQS(二)

    上一页介绍AQS其基本设计思路以及两个内部类Node和ConditionObject实现 聊聊高并发(二十一)解析java.util.concurrent各个组件(三) 深入理解AQS(一) 这篇说一 ...

  5. 十大经典数据挖掘算法(9) 朴素贝叶斯分类器 Naive Bayes

    贝叶斯分类器 贝叶斯分类分类原则是一个对象的通过先验概率.贝叶斯后验概率公式后计算,也就是说,该对象属于一类的概率.选择具有最大后验概率的类作为对象的类属.现在更多的研究贝叶斯分类器,有四个,每间:N ...

  6. HTML介绍JS

    首先,该脚本的链接插入HTML代码: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvU2h1aVRpYW5OYWlMdW8=/font/5a6L5L2T/f ...

  7. 设计模式 - 出厂模式(factory pattern) 详细说明

    出厂模式(factory pattern) 详细说明 本文地址: http://blog.csdn.net/caroline_wendy/article/details/27081511 工厂方法模式 ...

  8. DS-5/RVDS4.0变量初始化错误

    最近总是有各种调试时的错误,内存错误一般,我无意中发现的所有全局变量失败,也就是说,全局变量声明之后,颂值早期值误. 初值明明是0x12345674,最后变为了0xBA141234,出现了移位现象 測 ...

  9. [LeetCode258] Add Digits 非负整数各位相加

    题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one di ...

  10. java提高篇(十)-----强制类型转换

    在java中强制类型转换分为基本数据类型和引用数据类型两种,这里我们讨论的后者,也就是引用数据类型的强制类型转换. 在Java中由于继承和向上转型,子类可以非常自然地转换成父类,但是父类转换成子类则需 ...