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]的大小 ...
随机推荐
- java线程例子登山
Through its implementation, this project will familiarize you with the creation and execution of thr ...
- C++使用函数模板
函数模板: 函数模板是蓝图或处方功能,编译器使用其发电功能系列中的新成员. 第一次使用时,新的功能是创建.从功能模板生成的函数的实例称为模板或模板的实例.函数模板的开始是keywordtemplate ...
- 静态方法使用bean
java类中的代码 public class BidMsgUtil { private static Logger log = Logger.getLogger(BidMsgUtil.class); ...
- WPF命令參数CommandParameter
XAML代码例如以下: <Window x:Class="Demo006.MainWindow" xmlns="http://schemas.microsoft.c ...
- BackTrack5 (BT5)无线password破解教程WPA/WPA2-PSK无线password皴
昨天公布了BackTrack5 (BT5)无线weppassword破解教程之minidwep-gtk破解法一文,对BT5下破解wep无线password的简单方法做了介绍,今天奶牛为朋友们介绍下怎样 ...
- 使用C#和.NET 4编写的并行应用程序“多核并发编程的规则”
“多核并发编程的规则” 规则的描述如下 1. 并发编程的思想—这条规则就是要谨记并发编程思想进行设计,就像前边章节所提交的. 2. 面向抽象编程-你可以利用.NET4中的TPL提供 ...
- 【Jqurey EasyUI+Asp.net】---DataGrid增加、删、更改、搜
在前面写了两,但不知道如何完成,对比刚刚开始学这个,他们摸着石头过河,一步步.在最后两天DataGridCRUD融合在一起.因此份额.我希望像我这样谁是刚刚开始学习一些帮助. 直接主题酒吧. 它是说数 ...
- ps设计资料整理
零基础学会建立一个简单化妆品网站—前台设计篇1[PS画草图] http://xiebiji.com/2008/09/huazhuang4/?wptheme=Plainscape&ie=1 PS ...
- li排序
html <ul id="ul1"> <li>9</li> <li>2</li> <li>7</li& ...
- Java 将字节数组转化为16进制的多种方案
很多时候我们需要将字节数组转化为16进制字符串来保存,尤其在很多加密的场景中,例如保存密钥等.因为字节数组,除了写入文件或者以二进制的形式写入数据库以外,无法直接转为为字符串,因为字符串结尾有\0,当 ...