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]的大小 ...
随机推荐
- poj2348(博弈)
poj2348 给定两个数a,b,大的数能减少小的数的倍数,不能是的数小于0,谁先使得数等于0,谁就赢了 有三种情况 ① a % b ==0 这个状态是必胜的 ② a - b < b 这个状 ...
- FlexPaper二次开发问题及搜索高亮显示
原文:FlexPaper二次开发问题及搜索高亮显示 最近有个需求,做一个IT知识库,类似于文库,说到文库肯定会用到在线浏览文档了,所有在网上翻阅了一下类似豆丁的在线浏览器插件的资料,将其进行了二次开发 ...
- 配置jndi服务,javax.naming.NamingException的四种情况
1.当jndi服务没有启动,或者jndi服务的属性没有设置正确,抛出如下异常: javax.naming.CommunicationException: Can't find SerialContex ...
- 深入理解spring中的各种注解(转)
Spring中的注解大概可以分为两大类: 1)spring的bean容器相关的注解,或者说bean工厂相关的注解: 2)springmvc相关的注解. spring的bean容器相关的注解,先后有:@ ...
- 使用form的target属性屏蔽url跳
target: 指定公开赛, action URL. 关键点: 让target指向隐藏的iframe demo: form.jsp <%@ page language="java&qu ...
- sql server 数据库 只有mdf文件,如何附加
直接附加就可以,SQL 会提示LOG文件找不到,可删除提示的错误行,只附加MDF文件,附加成功后,SQL会自动创建LOG文件.
- 深入理解JavaScript系列(33):设计模式之策略模式(转)
介绍 策略模式定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化不会影响到使用算法的客户. 正文 在理解策略模式之前,我们先来一个例子,一般情况下,如果我们要做数据合法性验证,很 ...
- HDOJ 4424 Conquer a New Region
并检查集合 侧降序,每增加一个侧面应该推断,其中基本建设方..... Conquer a New Region Time Limit: 8000/4000 MS (Java/Others) Me ...
- Win10打不开chm文件的解决办法
在Win10系统中打开chm文件时,提示安全警告,如下图: 点击打开后,可以看到chm文件的目录大纲,但是点击任意目录其内容都是空白,如下图: 经过网络一通搜索,发现解决办法很简单,就是在上面的安装警 ...
- hibernate它5.many2one单向
关系数据库表之间的关系: 1 正确 1 1 正确 许多 许多 正确 许多 表间关系设计 基于主键关联 基于外键关联 基于中间表 1 对 1关系实现: 基于主键关联 基于外键关联 基于中间表 1 对 多 ...