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]的大小 ...
随机推荐
- docker 镜像中包含数据库环境和运行环境
需求: 一个镜像中要包含数据库环境和运行环境 Apache 环境 + mariadb 已经在拉取了Apache的运行环境 - 拉取代码 git https://github.com/timhaak/d ...
- Java实现平衡二叉树(AVLTree)的构建
近期在学习数据结构上关于平衡二叉树的知识,看了严老师的思路,感觉用java写出递归的构建方式有点困难,由于当中的递归须要把引用传进去,所以感觉是要实现起来比較麻烦,所以就首先想到使用非递归的方式来实现 ...
- Apple-Watch开发
Apple Watch界面设计规范(4) - 通知 Apple Watch界面设计规范(3) - Glance Apple Watch界面设计规范(2) - 应用解析 Apple Watch界面设计规 ...
- java 钱币的单位转换
将钱转成转换为带指定单位的钱 int money = 10; NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); System ...
- EF结合SqlBulkCopy在项目中的使用
这是我第一次写博客,由于水平有限,写不出什么好东西,还望见谅. 我现在参与的这个项目采用的是EF框架,方便了数据库的访问.但在实际中,发现项目中导入市县Excel数据耗时太长,于是趁这段时间专门研究了 ...
- Mysql在php5中的应用
1.PHP与mysql建立连接 php.ini加载mysql组件 extension=php_mysql.dll 前的;去掉 extension_dir=””路径是否正确 PHP连接mysql函数 m ...
- HibernateTool的安装和使用(Eclipse中)
http://blog.sina.com.cn/s/blog_919273e20101g1t7.html
- iOS 使用 FFmpeg
iOS 使用 FFmpeg 字数486 阅读288 评论7 喜欢5 集成 下载FFmpeg For iOS编译脚本: 打开 terminal 执行sh build-ffmpeg.sh: 步骤2执行完成 ...
- http错误代码含义大全详解
http 错误代码表 所有 HTTP 状态代码及其定义. 代码 指示 2xx 成功 200 正常:请求已完成. 201 正常:紧接 POST 命令. 202 正常:已接受用于处理, ...
- 十、C# 异常处理
1.多异常类型 2.捕捉异常 3.常规catch块 4.异常处理的指导原则 5.定义自定义异常 1.多异常类型 代码要引发任何异常,只需为要引发的异常实例实例附加关键字throw作为前缀.具体选择 ...