题目链接: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. 使用Xamarin在Visual Studio中开发Android应用

    原文:使用Xamarin在Visual Studio中开发Android应用 本文使用的环境是Windows 8 Visual Studio 2012.2 1.下载Xamarin http://xam ...

  2. linux sort,uniq,cut,wc命令详解 (转)

    sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些文件连接起来,并当作一个文件进行排序. sort语法 ...

  3. Windows 8 应用开发 - 异步调用

    原文:Windows 8 应用开发 - 异步调用     不论是桌面客户端还是Web应用通常会出现处理时间较长的操作,为了在这段时间内不影响用户与应用之间的交互体验,开发人员通常会使用异步调用技术,使 ...

  4. Android System Property 解析

    一 System Property       今天在折腾HDMI 显示,为Setting提供接口,遇到非常多跟Android系统属性相关的问题.因此,顺便分析和总结一些. android的代码中大量 ...

  5. HTML5游戏开发实战--当心

    1.WebSocket它是HTML5该标准的一部分.Web页面可以用它来连接到持久socketserver在.该接口提供一个浏览器和server与事件驱动的连接.这意味着client每次需要时不再se ...

  6. $.ajax通路RESTful Web Service一个错误:Unsupported Media Type

    最近项目,使用头版jquery ajax访问背景CXF发布时间rest维修,结果遇到了错误"Unsupported Media Type". 公布的服务java代码例如以下: im ...

  7. ViewData ViewBag ViewModel

    ViewBag 里可以携带dynamic的数据. Model 是从control传过来的模型数据. 我自己感觉ViewBag 可以携带少量的数据,但是我同事喜欢部分页partial 请求,ViewBa ...

  8. wind river hypervisor 2.0.2.1

    2692407267@qq.com,请注意很多其他内容http://user.qzone.qq.com/2692407267 wind river hypervisor 2.0.2.1 版权声明:本文 ...

  9. ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl 后篇 --事件冒泡

    原文:ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl 后篇 --事件冒泡 CompositeControl  后篇 --事件冒泡 系列文章链接: ASP.NET ...

  10. 花生壳宣布网站的网址直接绑定到详细的项目——jboss版本

    花生壳公布,首先要有域名.然后激活域名,详细的公布就不说了,网上有非常多资料,这里是在jboss下直接将网址与详细的项目相应.做法有点不地道 假设跟图上一样配置的话.訪问网址相当于訪问的是http:/ ...