注意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的更多相关文章

  1. Codeforces Round#251(Div 2)D Devu and his Brother

    --你以为你以为的.就是你以为的? --有时候还真是 题目链接:http://codeforces.com/contest/439/problem/D 题意大概就是要求第一个数组的最小值要不小于第二个 ...

  2. Codeforces Round #251 (Div. 2) B. Devu, the Dumb Guy

    注意数据范围即可 #include <iostream> #include <vector> #include <algorithm> using namespac ...

  3. Codeforces Round #251 (Div. 2) A - Devu, the Singer and Churu, the Joker

    水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...

  4. Codeforces Round 251 (Div. 2)

    layout: post title: Codeforces Round 251 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  5. 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 ...

  6. Codeforces Round #258 (Div. 2)E - Devu and Flowers

    题意:n<20个箱子,每个里面有fi朵颜色相同的花,不同箱子里的花颜色不同,要求取出s朵花,问方案数 题解:假设不考虑箱子的数量限制,隔板法可得方案数是c(s+n-1,n-1),当某个箱子里的数 ...

  7. 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 ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. 《CLR via C#》读书笔记(1)CLR执行模型

    1.1 释义 CLR 公共语音运行时 Common Language Runtime CTS 通用类型系统 Common Type System CTS.CLS是CLR的核心 CLS 通用语言规范 C ...

  2. java的final用法

    转自:http://blog.163.com/maomaoyu_1012/blog/static/19060130520116269329894/ 1.         修饰基础数据成员的final ...

  3. 编程风格规范google版

    python's  coding style,google 命名

  4. 声明replicated属性之后我编译不通过的问题

  5. 基于PHP+Ajax实现表单验证的详解

    一,利用键盘响应,在不刷新本页面的情况下验证表单输入是否合法 用户通过onkeydown和onkeyup事件来触发响应事件.使用方法和onclick事件类似.onkeydown表示当键盘上的键被按下时 ...

  6. Java eclipse下 Ant build.xml实例详解

    在有eclipse集成环境下ant其实不是很重要,但有些项目需要用到,另外通过eclipse来学习和理解ant是个很好的途径,所以写他demo总结下要点,希望能够帮到大家. 一.本人测试环境eclip ...

  7. loadrunner中lr_save_searched_string函数的使用

    控制abc后面的第几个字符: 控制字符长度: 总结: 实际应用: Action() { int i =0,j=0; char *tt_url = lr_eval_string("{tt_ur ...

  8. MySQL导入sql脚本 导出数据库

    导出数据库 不能停止服务 cd /var/lib/mysql (进入到MySQL库目录,根据自己的MySQL的安装情况调整目录) mysqldump -u用户名 -p 数据库名 > 导出的文件名 ...

  9. 07 JavaWeb

    软件开发的两种架构:c/s和b/s          * C/S     client/server     客户端/服务器     例子:QQ     快播     暴风影音...          ...

  10. PHP 传值和传引用、传地址的区别

    传值,   是把实参的值赋值给行参   那么对行参的修改,不会影响实参的值   传地址   是传值的一种特殊方式,只是他传递的是地址,不是普通的如int   那么传地址以后,实参和行参都指向同一个对象 ...