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”三种中任意一种就输 ...
随机推荐
- (转)ORA-12519: TNS:no appropriate service handler found 的问题处理。
很多时候出现:ORA-12519: TNS:no appropriate service handler found 都是由于当前的连接数已经超出他能够处理的最大值了. 处理方法如下:摘自网上. se ...
- Win10开机提示Resume from Hibernation该怎么办?
Windows10系统的电脑开机提示:Resume from Hibernation(从休眠恢复),这是电脑没有真正关机,而是上次关机时进入了[休眠状态],所以开机时提示:从休眠恢复.如何解决Wind ...
- static_cast、dynamic_cast、reinterpret_cast、const_cast以及C强制类型转换的区别
static_cast 1. 基础类型之间互转.如:float转成int.int转成unsigned int等 2. 指针与void*之间互转.如:float*转成void*.CBase*转成void ...
- 【leetcode】Candy
题目描述: There are N children standing in a line. Each child is assigned a rating value. You are giving ...
- DWZ分页、排序失效小结
1. 在视图文件中与分页相关的代码段 <form id="pagerForm" method="post" action="w_list.htm ...
- HDU 4005 The war Tarjan+dp
The war Problem Description In the war, the intelligence about the enemy is very important. Now, o ...
- html5 head头标签
桌面端开发中,meta标签通常用来为搜索引擎优化(SEO)及 robots定义页面主题,或者是定义用户浏览器上的cookie:它可以用于鉴别作者,设定页面格式,标注内容提要和关键字:还可以设置页面使其 ...
- SQLServer 维护脚本分享(05)内存(Memory)
--查看设置的最大最小每次 exec sp_configure 'max server memory (MB)' exec sp_configure 'min server memory (MB)' ...
- Blog Starting...
30出头,开始Blog记录学习生活的点滴,待40时再回来一看.
- 【POI】使用POI处理xlsx的cell中的超链接 和 插入图片 和 设置打印区域
使用POI对xlsx中插入超链接和 插入图片 package com.it.poiTest; import java.awt.image.BufferedImage; import java.io.B ...