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”三种中任意一种就输 ...
随机推荐
- 数据结构和算法 c#– 1.单项链表
1.顺序存储结构 Array 1.引用类型(托管堆) 2.初始化时会设置默认值 2.链式存储结构 2.1.单向链表 2.2.循环链表 2.3.双向链表
- 菜鸟学Linux命令:nohup命令启动程序
在UNIX/LINUX中,普通进程用&符号放到后台运行,如果启动该程序的控制台logout,则该进程随即终止. 要实现守护进程,一种方法是按守护进程的规则去编程,比较麻烦:另一种方法是仍然用普 ...
- Swipe JS – 移动WEB页面内容触摸滑动类库
想必做移动前端的同学经常会接到这样子的一个需求,就是在移动设备页面上的banner图能够用手指触摸左右或上下的滑动切换,这在移动设备是个很常见的一个效果,其用户体验远甚于点击一个按钮区域,通过手指的触 ...
- wp8 入门到精通 测量代码执行时间
Stopwatch time = new Stopwatch(); byte[] target = new byte[size]; for (int j = 0; j < size; j++) ...
- PHP二维数组去除重复,重复值相加
$arr = array( array('id' => 122, 'name' => '张三', 'amount' => '1'), array('id' => 123, 'n ...
- java BigInteger使用
虽然说我不怎么会用java写一些东西,但是java里的biginteger我还是很喜欢的.这个类解决了,我们在其他很多语言中遇到的问题:大数.比如在C++中我们要计算一个大小超过long long的数 ...
- C可变参数函数 实现
转自:http://blog.csdn.net/weiwangchao_/article/details/4857567 C函数要在程序中用到以下这些宏: void va_start( va_list ...
- pythonchallenge之C++学习篇-03
提示说一个小写字母两面精确地被大写字母包围,应该指的是周围没有四个而仅仅这两个像这样的:xXXXxXXXx的中间的那个应该是符合条件的 好了标题是re,提示该是使用正则表达式,网页源码里有待处理的字符 ...
- jquery中append()、prepend()、after()、before()的区别详解
append() - 在被选元素的结尾插入内容(内容的结尾,比如说有个a标签,则是在</a>这个标签之前添加东西) prepend() - 在被选元素的开头插入内容(内容的开始,比如说有个 ...
- cocoaPads 安装及出现Analyzing dependencies之后卡死解决方案
1.安装 a. 查看源 gem sources -l b. 设置源: sudo gem sources -a http://ruby.taobao.org c. 删除源:sudo gem source ...