注意p的边界情况,p为0,或者 p为k

奇数+偶数 = 奇数

奇数+奇数 = 偶数

  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <algorithm>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. int main(){
  10. int n,k,p;
  11. long a;
  12. cin >> n >> k >> p;
  13. vector<long> even, odd;
  14. vector<set<long> > parts(k);
  15. for(int i = ; i < n ; ++ i){
  16. cin >> a;
  17. a% ? odd.push_back(a): even.push_back(a);
  18. }
  19. int even_cnt = p, odd_cnt = k - p;
  20. if(odd.size() < odd_cnt || (odd.size() -odd_cnt)% ) cout<<"NO"<<endl;
  21. else{
  22. for(int i = p; i < k ; ++ i) parts[i].insert(odd[i-p]);
  23. if(even.size()+(odd.size()-odd_cnt)/ < p) cout<<"NO"<<endl;
  24. else{
  25. if(even.size() >= p){
  26. for(int i = ; i < p; ++ i) parts[i].insert(even[i]);
  27. for(int i = p; i < even.size(); ++ i) parts[p- >= ? p- : p].insert(even[i]);
  28. for(int i = k-p; i < odd.size() ; ++ i ) parts[p- >= ? p- : p].insert(odd[i]);
  29.  
  30. }else{
  31. for(int i = ; i < even.size(); ++ i) parts[i].insert(even[i]);
  32. int j = k-p;
  33. for(int i = even.size(); i < p-; ++ i) parts[i].insert(odd[j++]),parts[i].insert(odd[j++]);
  34. while( j < odd.size()) parts[p- >= ? p- : p].insert(odd[j++]);
  35. }
  36. cout<<"YES"<<endl;
  37. for(int i = ; i < k; ++ i){
  38. set<long> tmp = parts[i];
  39. cout<<tmp.size();
  40. for(set<long>::iterator iter = tmp.begin(); iter!=tmp.end(); ++ iter) cout<<" "<<*iter;
  41. cout<<endl;
  42. }
  43. }
  44. }
  45. }

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. 数据结构和算法 c#– 1.单项链表

    1.顺序存储结构 Array 1.引用类型(托管堆) 2.初始化时会设置默认值   2.链式存储结构 2.1.单向链表 2.2.循环链表 2.3.双向链表

  2. 菜鸟学Linux命令:nohup命令启动程序

    在UNIX/LINUX中,普通进程用&符号放到后台运行,如果启动该程序的控制台logout,则该进程随即终止. 要实现守护进程,一种方法是按守护进程的规则去编程,比较麻烦:另一种方法是仍然用普 ...

  3. Swipe JS – 移动WEB页面内容触摸滑动类库

    想必做移动前端的同学经常会接到这样子的一个需求,就是在移动设备页面上的banner图能够用手指触摸左右或上下的滑动切换,这在移动设备是个很常见的一个效果,其用户体验远甚于点击一个按钮区域,通过手指的触 ...

  4. wp8 入门到精通 测量代码执行时间

    Stopwatch time = new Stopwatch(); byte[] target = new byte[size]; for (int j = 0; j < size; j++) ...

  5. PHP二维数组去除重复,重复值相加

    $arr = array( array('id' => 122, 'name' => '张三', 'amount' => '1'), array('id' => 123, 'n ...

  6. java BigInteger使用

    虽然说我不怎么会用java写一些东西,但是java里的biginteger我还是很喜欢的.这个类解决了,我们在其他很多语言中遇到的问题:大数.比如在C++中我们要计算一个大小超过long long的数 ...

  7. C可变参数函数 实现

    转自:http://blog.csdn.net/weiwangchao_/article/details/4857567 C函数要在程序中用到以下这些宏: void va_start( va_list ...

  8. pythonchallenge之C++学习篇-03

    提示说一个小写字母两面精确地被大写字母包围,应该指的是周围没有四个而仅仅这两个像这样的:xXXXxXXXx的中间的那个应该是符合条件的 好了标题是re,提示该是使用正则表达式,网页源码里有待处理的字符 ...

  9. jquery中append()、prepend()、after()、before()的区别详解

    append() - 在被选元素的结尾插入内容(内容的结尾,比如说有个a标签,则是在</a>这个标签之前添加东西) prepend() - 在被选元素的开头插入内容(内容的开始,比如说有个 ...

  10. cocoaPads 安装及出现Analyzing dependencies之后卡死解决方案

    1.安装 a. 查看源 gem sources -l b. 设置源: sudo gem sources -a http://ruby.taobao.org c. 删除源:sudo gem source ...