Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
注意p的边界情况,p为0,或者 p为k
奇数+偶数 = 奇数
奇数+奇数 = 偶数
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath> using namespace std; int main(){
int n,k,p;
long a;
cin >> n >> k >> p;
vector<long> even, odd;
vector<set<long> > parts(k);
for(int i = ; i < n ; ++ i){
cin >> a;
a% ? odd.push_back(a): even.push_back(a);
}
int even_cnt = p, odd_cnt = k - p;
if(odd.size() < odd_cnt || (odd.size() -odd_cnt)% ) cout<<"NO"<<endl;
else{
for(int i = p; i < k ; ++ i) parts[i].insert(odd[i-p]);
if(even.size()+(odd.size()-odd_cnt)/ < p) cout<<"NO"<<endl;
else{
if(even.size() >= p){
for(int i = ; i < p; ++ i) parts[i].insert(even[i]);
for(int i = p; i < even.size(); ++ i) parts[p- >= ? p- : p].insert(even[i]);
for(int i = k-p; i < odd.size() ; ++ i ) parts[p- >= ? p- : p].insert(odd[i]); }else{
for(int i = ; i < even.size(); ++ i) parts[i].insert(even[i]);
int j = k-p;
for(int i = even.size(); i < p-; ++ i) parts[i].insert(odd[j++]),parts[i].insert(odd[j++]);
while( j < odd.size()) parts[p- >= ? p- : p].insert(odd[j++]);
}
cout<<"YES"<<endl;
for(int i = ; i < k; ++ i){
set<long> tmp = parts[i];
cout<<tmp.size();
for(set<long>::iterator iter = tmp.begin(); iter!=tmp.end(); ++ iter) cout<<" "<<*iter;
cout<<endl;
}
}
}
}
Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array的更多相关文章
- Codeforces Round#251(Div 2)D Devu and his Brother
--你以为你以为的.就是你以为的? --有时候还真是 题目链接:http://codeforces.com/contest/439/problem/D 题意大概就是要求第一个数组的最小值要不小于第二个 ...
- Codeforces Round #251 (Div. 2) B. Devu, the Dumb Guy
注意数据范围即可 #include <iostream> #include <vector> #include <algorithm> using namespac ...
- Codeforces Round #251 (Div. 2) A - Devu, the Singer and Churu, the Joker
水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...
- Codeforces Round 251 (Div. 2)
layout: post title: Codeforces Round 251 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #258 (Div. 2) E. Devu and Flowers 容斥
E. Devu and Flowers 题目连接: http://codeforces.com/contest/451/problem/E Description Devu wants to deco ...
- Codeforces Round #258 (Div. 2)E - Devu and Flowers
题意:n<20个箱子,每个里面有fi朵颜色相同的花,不同箱子里的花颜色不同,要求取出s朵花,问方案数 题解:假设不考虑箱子的数量限制,隔板法可得方案数是c(s+n-1,n-1),当某个箱子里的数 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- HTML5学习之WebSocket通讯(六)
WebSocket是下一代客户端-服务器的异步通信方法. WebSocket最伟大之处在于服务器和客户端可以在任意时刻相互推送信息 WebSocket允许跨域通信 Ajax技术需要客户端发起请求,We ...
- ArchLinux 安装笔记 --zz
为何安装 ArchLinux 为了更深层次的理解 Linux (其实只是闲的蛋疼 准备安装介质 U盘首选,没有之一.自己的本子是 MBR 的,UEFI 神马的我才不知道呢哼! 制作 U 盘启动: Li ...
- JavaScript之作用域与闭包详解
前言: JavaScript是一种应用非常广泛的语言,其也有一些自身特点和优势,本文重在讲述其作用域机制以及闭包,会从一些实例来探讨其机理. 作用域在JavaScript程序员日常使用中有不同的含义, ...
- UVA11542 Square(高斯消元 异或方程组)
建立方程组消元,结果为2 ^(自由变元的个数) - 1 采用高斯消元求矩阵的秩 方法一: #include<cstdio> #include<iostream> #includ ...
- windows下mongodb安装与使用整理
一.首先安装mongodb 1.下载地址:http://www.mongodb.org/downloads 2.解压缩到自己想要安装的目录,比如d:\mongodb 3.创建文件夹d:\mongodb ...
- SQL Server 创建表 添加主键 添加列常用SQL语句
--删除主键 alter table 表名 drop constraint 主键名 --添加主键 alter table 表名 add constraint 主键名 primary key(字段名1, ...
- 【MongoDB】2.可视化工具的安装和使用
首先:关于 能支持MongoDB新版本的可视化工具,争议不断,各人都有各人的支持. 因此之前选择安装的时候就安装了MongoDB 3.0.14版本的. 最终,确定使用Robomongo作为我第一个 ...
- 【MyEcplise 插件】反编译插件jad
jad是一个使用比较广泛的反编译插件. 这里说如何将jad安装到My Ecplise中. 1.下载jad的jar http://nchc.dl.sourceforge.net/project/jadc ...
- css新增选择器
- mysql数据库管理工具sqlyog在首选项里可以设置默认查询分页条数和字体,改写关键字大小写
sqlyog设置一直习惯用sqlyog来管理mysql数据库,但有三个地方用得不是很爽:1.默认查询条数只有1000条经常需要勾选掉重新查询.2.自动替换关键字大小写,有时候字段名为关键字的搞成大写的 ...