Codeforces 439C Devu and Partitioning of the Array(模拟)
题目链接: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(模拟)的更多相关文章
- codeforces 439C Devu and Partitioning of the Array(烦死人的多情况的模拟)
题目 //这是一道有n多情况的烦死人的让我错了n遍的模拟题 #include<iostream> #include<algorithm> #include<stdio.h ...
- 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 ...
- CF 439C Devu and Partitioning of the Array
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:1 second memory limit per test: ...
- 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 ...
- codeforces 439D Devu and Partitioning of the Array(有深度的模拟)
题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...
- codeforces C. Devu and Partitioning of the Array
题意:给你n个数,然后分成k部分,每一个部分的和为偶数的有p个,奇数的有k-p个,如果可以划分,输出其中的一种,不可以输出NO; 思路:先输出k-p-1个奇数,再输出p-1个偶数,剩余的在进行构造. ...
- 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 ...
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
注意p的边界情况,p为0,或者 p为k 奇数+偶数 = 奇数 奇数+奇数 = 偶数 #include <iostream> #include <vector> #include ...
- 【Henu ACM Round#20 D】 Devu and Partitioning of the Array
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一开始所有的数字单独成一个集合. 然后用v[0]和v[1]记录集合的和为偶数和奇数的集合它们的根节点(并查集 然后先让v[0]的大小 ...
随机推荐
- Linux命令对应的全称解释(转)
Filesystem Hierarchy Standard(FHS) /:根目录,所有的目录.文件.设备都在/之下,/就是Linux文件系统的组织者,也是最上级的领导者. /bin:bin 就是二进 ...
- simplePagination API
simplePagination API simplePagination.js 一个简单的jQuery分页插件,主题和Bootstrap支持CSS 3 分页button样式 "light- ...
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
1.错误叙述性说明 2014-7-10 23:12:23 org.apache.catalina.core.StandardContext filterStart 严重: Exception star ...
- 比量iOS6/iOS7, 3.5inch/4.0inch
Retina (3.5/4 inch Screen) or Non-Retina 比量 if ([[UIScreen mainScreen] respondsToSelector:@selector( ...
- Copy-and-swap
为了在自己定义类里重载一个异常安全(exception safe)的赋值操作符.创造了一个这种习惯用语.也叫:Create-Temporary-and-Swap. 要想写健壮的C++代码.异常安全很重 ...
- OTN&互换amp; P-OTN有效降低100G 网络成本 (两)
OTN互换& P-OTN有效降低100G 网络成本 (两) 在全球范围内.网流量的增长速度是空前的,导致此现象的缘由包含云服务的增长.移动宽带和基于互联网的视频点播服务的增长. Cisco估计 ...
- 正确使用Git Flow
Git 在团队中的最佳实践--如何正确使用Git Flow 我们已经从SVN 切换到Git很多年了,现在几乎所有的项目都在使用Github管理, 本篇文章讲一下为什么使用Git, 以及如何在团队中正确 ...
- 最常用的动态sql语句梳理Mybatis(转)
公司项目中一直使用Mybatis作为持久层框架,自然,动态sql写得也比较多了,最常见的莫过于在查询语句中使用if标签来动态地改变过滤条件了.Mybatis的强大特性之一便是它的动态sql,免除了拼接 ...
- xml它解析----DOM解析
DOM模型(documentobject model) •DOM解析器在解析XML文档时,会把文档中的全部元素,依照其出现的层次关系.解析成一个个Node对象(节点). •在dom中.节点之间关系例如 ...
- ORACLE profile列4 --CREATE PROFILE
这个博客是ORACLE profile系列第四部分.主要说一下,假设你创建profile而使用profile资源和password控制 CREATE PROFILE Note: Oracle reco ...