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 ...
随机推荐
- Error:“const char*”类型的实参与“wchar_t”类型的形参不兼容
MainApp\RPolarView.cpp(1571): error C2664: “ATL::CStringT<BaseType,StringTraits>::ReverseFind” ...
- BAPI、badi 和 LSMW 的相同点和不同点及具体操作
一开始badi.BAPI.LSMW关系极其混乱,好像都是传输数据, just transfer data from SAP system to non-SAP system or transfer d ...
- 使用PHP创建一个socket服务端
与常规web开发不同,使用socket开发可以摆脱http的限制.可自定义协议,使用长连接.PHP代码常驻内存等.学习资料来源于workerman官方视频与文档. 通常创建一个socket服务包括这几 ...
- A Secret(KMP)
A Secret Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 256000/256000 K (Java/Others)Total ...
- JavaScript跳出iframe框架
一.window.top top属性返回最顶层的先辈窗口. 该属性返回对一个顶级窗口的只读引用.如果窗口本身就是一个顶级窗口,top属性存放对窗口自身的引用.如果窗口是一个框架,那么top属性引用包含 ...
- JavaScript通过preventDefault()使input[type=text]禁止输入但保留光标
一.说明 取消事件的默认动作. 该方法将通知 Web 浏览器不要执行与事件关联的默认动作(如果存在这样的动作).例如,如果 type 属性是 "submit",在事件传播的任意阶段 ...
- JavaWeb 之文件上传
1. 文件上传的要求 1.1 上传对表单的限制 method="post"; enctype="multipart/form-data"; 表单中需要添加文件表 ...
- Python排列组合
product 笛卡尔积 (有放回抽样排列) permutations 排列 (不放回抽样排列) combinations 组合,没有重复 (不放回抽样组合) combinations_with_re ...
- Java并发—线程池框架Executor总结(转载)
为什么引入Executor线程池框架 new Thread()的缺点 每次new Thread()耗费性能 调用new Thread()创建的线程缺乏管理,被称为野线程,而且可以无限制创建,之间相互竞 ...
- 20170523 BSEG替代付款条件-ZTERM 天数-ZBD1T
增强方式:替代,[替代基本用在FICO模块]BTE增强方式应用更广,需要学习总结. 程序:ZRGGBS* 步骤 1,SE16N:GB01 将 ZBD1T排除标记置为空,[注意,此更改跨client,d ...