codeforces C. Devu and Partitioning of the Array
题意:给你n个数,然后分成k部分,每一个部分的和为偶数的有p个,奇数的有k-p个,如果可以划分,输出其中的一种,不可以输出NO;
思路:先输出k-p-1个奇数,再输出p-1个偶数,剩余的在进行构造。 奇数+奇数=偶数。
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#define maxn 1000100
#define ll long long
using namespace std; int n,k,p;
ll a[maxn];
vector<int>qq;
vector<int>pp; int main()
{
scanf("%d%d%d",&n,&k,&p);
for(int i=; i<=n; i++)
{
scanf("%lld",&a[i]);
if(a[i]%==) qq.push_back(a[i]);
else if(a[i]%!=) pp.push_back(a[i]);
}
int odd=pp.size();
int even=qq.size();
if(odd<k-p||(odd>=k-p&&even+(odd-(k-p))/<p)||(odd-(k-p))%==)
printf("NO\n");
else
{
printf("YES\n");
for(int i=; i<k-p-; i++)
{
printf("%d %d\n",,pp[i]);
}
int x=k-p-;
int y=even;
if(x<)x=;
for(int i=; i<p-; i++)
{
if(y)
{
printf("%d %d\n",,qq[y-]);
y--;
}
else
{
printf("%d %d %d\n",,pp[x],pp[x+]);
x+=;
}
}
if(k-p!=&&p)
{
printf("%d %d\n",,pp[x]);
x++;
}
if(x<) x=;
printf("%d ",y+odd-x);
while(y)
{
printf("%d ",qq[y-]);
y--;
}
while(x<odd)
{
printf("%d ",pp[x]);
x++;
}
printf("\n");
}
return ;
}
codeforces C. Devu and Partitioning of the Array的更多相关文章
- Codeforces 439C Devu and Partitioning of the Array(模拟)
题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数 ...
- codeforces 439D Devu and Partitioning of the Array(有深度的模拟)
题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...
- codeforces 439C Devu and Partitioning of the Array(烦死人的多情况的模拟)
题目 //这是一道有n多情况的烦死人的让我错了n遍的模拟题 #include<iostream> #include<algorithm> #include<stdio.h ...
- codeforces 251 div2 C. Devu and Partitioning of the Array 模拟
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...
- CodeForce 439C Devu and Partitioning of the Array(模拟)
Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes ...
- CF 439C Devu and Partitioning of the Array
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:1 second memory limit per test: ...
- CF 439C(251C题)Devu and Partitioning of the Array
Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes ...
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
注意p的边界情况,p为0,或者 p为k 奇数+偶数 = 奇数 奇数+奇数 = 偶数 #include <iostream> #include <vector> #include ...
- 【Henu ACM Round#20 D】 Devu and Partitioning of the Array
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一开始所有的数字单独成一个集合. 然后用v[0]和v[1]记录集合的和为偶数和奇数的集合它们的根节点(并查集 然后先让v[0]的大小 ...
随机推荐
- muduo网络库使用心得
上个月看了朋友推荐的mudo网络库,下完代码得知是国内同行的开源作品,甚是敬佩.下了mudo使用手冊和035版的代码看了下结构,感觉是一个比較成熟并且方便使用的网络库.本人手头也有自己的网络库,尽管不 ...
- Java语言基础(七)
Java语言基础(七) 今天在公司多呆了会,回来晚了 一.自动类型转换 在Java中,数据是可以转换的 例如可以将byte类型的赋给int类型的 这里希望你了解内存的变化,例如 在这里,我想你应该知 ...
- 去掉android点击事件产生的半透明蓝色背景
在wap开发过程当中,当你点击一个链接或者通过Javascript定义的可点击元素的时候,它就会出现一个半透明的蓝色背景,若要重设这个表现 ,可以利用css3: *{ -webkit-tap-high ...
- python模拟登陆之下载
好长时间没有更新博客了,哈哈. 今天公司给了这么一个需求,现在我们需要去淘宝获取上一天的订单号,然后再根据订单号去另一个接口去获取订单详情,然后再给我展示到web! 中间涉及到的技术点有: 模拟登陆 ...
- eclipse-SDK-3.7-win32;eclipse-java-indigo-win32;eclipse-jee-indigo-win32 区别(ZZ)
eclipse-SDK-3.7-win32:eclipse-java-indigo-win32:eclipse-jee-indigo-win32 三个都是用于win32,即windows系统的32位机 ...
- git 指令汇总
学习git过程中整理的笔记: git add 添加文件到暂存区: git commit -m "更改说明" 提交文件更改: git status 查看当前文件状态: git dif ...
- Css实现透明效果,兼容IE8
Css实现透明效果,兼容IE8 >>>>>>>>>>>>>>>>>>>>> ...
- alpha属性设置
alpha是来设置透明度的,它的基本属性是filter:alpha(opacity,finishopacity,style,startX,startY,finishX,finishY).opacity ...
- git语言
安装完成后,需要进一步设置用户名和email.因为git是分布式版本控制工具,因此需要每台开发机自报家门. $ git config --global user.name "Your Nam ...
- @ManyToMany中间表附加字段设计
在使用@ManyToMany时,若中间表只有相应的外键字段可以直接建立两个对应的Entity 设置ManyToMany @ManyToMany 两个表多对多关联 但若是中间表有自己的附加字段,这需要为 ...