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]的大小 ...
随机推荐
- 网络子系统43_ip选项预处理
//选项格式: // 1.type中指示该选项在分片时是否需要被拷贝 // 2.ptr从1算起,1为type的位置 // 3.len不包括type字段,其余都包括(len,ptr,选项内容) //ty ...
- [Javascript] Modifying an Immutable.js Map()
We will now look at five methods that modify an Immutable.Map(). set update delete clear merge //set ...
- Android自定义drawable(Shape)详解
在Android开发过程中,经常需要改变控件的默认样式, 那么通常会使用多个图片来解决.不过这种方式可能需要多个图片,比如一个按钮,需要点击时的式样图片,默认的式样图片. 这样就容易使apk变大. 那 ...
- 如何设计一个简单的C++ ORM
2016/11/15 "没有好的接口,用C++读写数据库和写图形界面一样痛苦" 阅读这篇文章前,你最好知道什么是 Object Relation Mapping (ORM) 阅读这 ...
- xslt语法之---position()函数
最近在学习使用XSLT,很好很强大的样式表语言.使用到了position()函数特此记录一下. position()函数--返回节点位置 语法:position() 参数:无 返回值:整数 用途:该函 ...
- css考核点整理(三)-css选择器的使用
css选择器的使用
- sublime的js调试环境(基于node环境)
很多的语言都有控制台,都要专门的ide,js,用sublime在node的环境下,可以配置console, 如何配置?首先,要有node的环境,下载安装,还要安装到c盘才行,然后找到'工具(tool) ...
- try{}catch(){}//根据异常信息使用不同的方法要怎么实现
try{ }catch(Exception e){ if(e.getMessage().contains("123456798")) //使用e.getMessage().cont ...
- windows Server 2008 -必须使用“角色管理工具”安装或配置Microsoft .Net Framework 3.5
在windows Server 2008上安装 .Net Framework 3.5的时候,报错:必须使用“角色管理工具”安装或配置Microsoft .Net Framework 3.5. Solu ...
- eclipse中修改内存