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 ...
随机推荐
- iOS --提取本地<通讯录>数据 <1>
#pragma mark - 获取手机所有联系人 - (void)obtainPhoneAllContact { //这个变量用于记录授权是否成功,即用户是否允许我们访问通讯录 ; //声明一个通讯簿 ...
- linux 下shell程序(二)
输入和输出 输入指的是Shell程序读入数据.有从文件读取.从用户输入读取等方式读入数据.输出指的是Shell程序的运行 结果的处理,可以显示到屏幕或保存到文件. 用ceho命令输出结果 echo $ ...
- [Spring MVC]学习笔记--@RequestMapping支持的返回类型
下面针对官方文档列出的支持类型进行举例. (本篇例子存于github上, https://github.com/lemonbar/spring-mvc-requestmapping) 可以直接下载, ...
- P2424 约数和
题目背景 Smart最近沉迷于对约数的研究中. 题目描述 对于一个数X,函数f(X)表示X所有约数的和.例如:f(6)=1+2+3+6=12.对于一个X,Smart可以很快的算出f(X).现在的问题是 ...
- IIPP迷你项目(二)"Guess the Number!"
本来这个程序是早就编完了的,一直没时间发布博客.时至今日已时隔多天,也算是复习一下事件驱动型编程的过程吧. 1 事件驱动型编程 本质上这次的作业是披着猜数字皮的图形化界面编程,好在 simplegui ...
- 进程 query foreach
http://php.net/manual/en/pdo.query.php PDO::query() executes an SQL statement in a single function c ...
- recursion
w recursion nexttoken
- 如何查看l操作系统是否开启rpc服务
linux操作系统 在linux 5.X以及下的版本你可以通过service portmap status命令查看rpc是否启动.如果提示running,表示正在运行:如果提示stop就是关闭了.如果 ...
- 我的Android进阶之旅------>Android知识图谱
Android知识图谱,快来看看哪方面有漏洞? 该图转自:http://blog.csdn.net/xyz_lmn/article/details/41411355
- 《Python数据分析》笔记——数据可视化
数据可视化 matplotlib绘图入门 为了使用matplotlib来绘制基本图像,需要调用matplotlib.pyplot子库中的plot()函数 import matplotlib.pyplo ...