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]的大小 ...
随机推荐
- 挺好用的SQLSERVER数据库自动备份工具SQLBackupAndFTP(功能全面)
原文:挺好用的SQLSERVER数据库自动备份工具SQLBackupAndFTP(功能全面) 挺好用的SQLSERVER数据库自动备份工具SQLBackupAndFTP(功能全面) 这个工具主要就是自 ...
- Red Gate系列之三 SQL Server 开发利器 SQL Prompt 5.3.4.1 Edition T-SQL智能感知分析器 完全破解+使用教程
原文:Red Gate系列之三 SQL Server 开发利器 SQL Prompt 5.3.4.1 Edition T-SQL智能感知分析器 完全破解+使用教程 Red Gate系列之三 SQL S ...
- Cocos2d-x 3.2 Lua演示样例 XMLHttpRequestTest(Http网络请求)
Cocos2d-x 3.2 Lua演示样例 XMLHttpRequestTest(Http网络请求) 本篇博客介绍Cocos2d-x 3.2Lua演示样例中的XMLHttpRequestTes ...
- 【leetcode】LRU
import java.util.HashMap; import java.util.Map; public class LRUCache { private int capacity; privat ...
- Linux使用快捷键,who命令,rm命令,ps命令,cd,命令kill命令,find命令,grep命令,tar命令(gz、tar、bz2),用户管理,vim配置的一部分,相关命令
1.进入Ubuntu开场后的终端窗口的快捷键是: ctrl + alt+t:通过这个命令能够打开终端. ctrl + alt+t:通过这个命令能够打开终端. 再开一个tab选项卡式 ...
- SessionA和pplication网上聊天室的网络范例
login.aspx码,如以下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile=" ...
- 採訪The Molasses Flood:BioShock Infinite 游戏之后又一大作
Xsolla有幸与Flame in the Flood游戏的开发人员之中的一个-----Forrest Dowling进行了採訪,Flame in the Flood这款非常棒的游戏在Kickstar ...
- Oracle 闪回表实验
工:闪回表实验 1.结构测试表flb_test,数据不小于10000行: TEST_USER1@PROD>create table flb_test(id number,dd date); Ta ...
- Singleton模式线程相关的(C\C++)
这种需求的最新发展. 我需要一个静态类,无论地方,我可以在线程中调用它public功能对应的功能已经完成. 这个静态类会调用我初始化给它的一个指针,这个指针是与线程一一相应的: 准确来说这样的模式应该 ...
- cocos2dx-2.x CCFileUtils文件管理分析(2)
于1于,我只是对整体结构进行了分析,然后,2于,我会在一些我们经常使用的分析功能. //获取给定文件名称的全路径 //以下这非常长一段凝视.通过举样例,像我们说明cocos2dx获取文件全路径的规则. ...