codeforces 439C 模拟
http://codeforces.com/problemset/problem/439/C
题意:给你n个数,分成k个非空集合,其中有p个集合的元素和为偶数,其余k-p个集合的元素和为奇数。
思路:考虑两个数和的情况,奇+奇=偶,奇+偶=奇,偶+偶=偶。所以解决方案不存在的情况为
(oddnum<k-p || (oddnum-(k-p))%2!=0 || evennum+(oddnum-(k-p))/2<p)。
先输出k-p-1组的单个奇数,输出p-1组偶数(先为单个偶数,偶数不够两个奇数),若(k!=0&&k-p!=0),输出一个奇数,其余数一组输出。
#include<cstdio>
#include<iostream>
using namespace std;
int even[],odd[];
int main() {
int n,k,p,evennum=,oddnum=;
int dig;
scanf("%d%d%d",&n,&k,&p);
for(int i=;i<n;i++) {
scanf("%d",&dig);
if(dig%==) even[evennum++]=dig;
else odd[oddnum++]=dig;
}
if(oddnum<k-p || (oddnum-(k-p))%!=) printf("NO\n");
else {
if((evennum+(oddnum-(k-p))/)<p) printf("NO\n");
else {
int e=evennum,o=oddnum;
printf("YES\n");
int a;
for(a=;a<k-p-;a++) {
printf("1 %d\n",odd[a]);o--;
}
int j=a;
for(int i=;i<p-;i++) {
if(e>) {
printf("1 %d\n",even[i]);
e--;
}
else {
printf("2 %d %d\n",odd[j++],odd[j++]);
o-=;
}
}
if(p!=&&k-p!=) {
printf("1 %d\n",odd[j]);o--;
}
printf("%d ",o+e);
for(int i=evennum-e;i<evennum;i++) printf("%d ",even[i]);
for(int i=oddnum-o;i<oddnum;i++) printf("%d ",odd[i]);
printf("\n");
}
}
return ;
}
codeforces 439C 模拟的更多相关文章
- Codeforces 439C Devu and Partitioning of the Array(模拟)
题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数 ...
- codeforces 439C Devu and Partitioning of the Array(烦死人的多情况的模拟)
题目 //这是一道有n多情况的烦死人的让我错了n遍的模拟题 #include<iostream> #include<algorithm> #include<stdio.h ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- CodeForces - 404B(模拟题)
Marathon Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- Codeforces 709B 模拟
B. Checkpoints time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- CodeForces - 404A(模拟题)
Valera and X Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- Codeforces 390A( 模拟题)
Inna and Alarm Clock Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64 ...
- Codeforces 452D [模拟][贪心]
题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...
- CodeForces - 796B 模拟
思路:模拟移动即可,如果球落入洞中停止移动.注意:有可能第一个位置就是洞!! AC代码 #include <cstdio> #include <cmath> #include ...
随机推荐
- poj 2195(KM求最小权匹配)
题目链接:http://poj.org/problem?id=2195 思路:我们都知道KM使用来求最大权匹配的,但如果要求最小权匹配,只需把图中的权值改为负值,求一次KM,然后权值和取反即可. ht ...
- python3----冒泡排序
array = [1, 6, 7, 2, 9, 4] for i in range(len(array)-1, 1, -1): for j in range(0, i): if array[j] &g ...
- OpenCV学习笔记十八:opencv_flann模块
一,简介: Fast Library for Approximate Nearest Neighbors (FLANN)算法库.
- lumen 单元测试
laravel学院:http://laravelacademy.org/post/238.html 简书:https://www.jianshu.com/p/d8b3ac2c4623 问题解决:htt ...
- urllib基本使用 urlopen(),Request
urllib包含的常用模块:import urllib.request # 打开和读取url请求import urllib.error # 异常处理模块import urllib.parse # ur ...
- 【BZOJ2140】稳定婚姻 Tarjan
[BZOJ2140]稳定婚姻 Description 我国的离婚率连续7年上升,今年的头两季,平均每天有近5000对夫妇离婚,大城市的离婚率上升最快,有研究婚姻问题的专家认为,是与简化离婚手续有关. ...
- 1154 回文串划分(DP+Manacher)
1154 回文串划分 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 有一个字符串S,求S最少可以被划分为多少个回文串. 例如:abbaabaa,有多种划分方式. ...
- EasyUI 相关
根据关键字值取行 var rowIndex = $('#tt').datagrid('getRowIndex', id);//id是关键字值 var data = $('#tt').datagrid( ...
- jQuery 文档操作方法(append)
这些方法对于 XML 文档和 HTML 文档均是适用的,除了:html(). 一.append() 方法 append() 方法在被选元素的结尾(仍然在内部)插入指定内容. 例子: <html& ...
- [转载]H5项目常见问题汇总及解决方案
本文转载自:http://www.open-open.com/lib/view/open1449325854077.html Meta基础知识: H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 / ...