Codeforces 439C
比赛时间没能通过==, 只能说明自己代码写的太不严谨咯!
解题思想就是贪心
先判断无解的情况:
1. 奇数不够,因为偶数是无法凑成奇数的
2. 偶数不够,2个奇数可以凑成一个偶数
3. 在奇数够用的情况下, 先在k-p堆中每一堆都放一个奇数,
那么剩余的奇数个数一定是个偶数,否则必定会有另外一堆数的和也为奇数。
有解的情况,先放奇数, 每堆一个奇数。接下来要考虑偶数个数 < p的情况,
也就是用两个奇数来凑一个偶数,输出k-1堆后,有解的情况可以保证最后一堆
一定是满足条件的,也就是全部输出。
附上代码:
n, k, p = map(int, raw_input().split());
a = map(int, raw_input().split());
b, c = [], [];
even, odd = 0, 0;
for i in xrange(n):
if a[i] % 2 == 0:
even += 1
b.append(a[i]);
else:
c.append(a[i]);
odd = n - even;
if odd < k-p or (odd-(k-p))/2+even < p or (odd-(k-p))%2:
print "NO"
else:
print "YES";
for i in xrange(k-p-1):
print 1, c[i]
if p == 0:
print n-(k-p-1),
for i in xrange(k-p-1, odd):
print c[i],
for i in xrange(0, even):
print b[i],
else:
if k != p:
print 1, c[k-p-1]
j = k - p;
if even >= p and p:
for i in xrange(p-1):
print 1, b[i]
left = n - (k-p) - (p-1)
print left,
for i in xrange(k-p, odd):
print c[i],
for i in xrange(p-1, even):
print b[i],
elif even < p and p:
for i in xrange(even):
print 1, b[i]
for i in xrange(p-even-1):
print 2, c[j], c[j+1]
j += 2
left = n - even - j;
print left,
for i in xrange(j, j+left):
print c[i],
Codeforces 439C的更多相关文章
- Codeforces 439C Devu and Partitioning of the Array(模拟)
题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数 ...
- codeforces 439C 模拟
http://codeforces.com/problemset/problem/439/C 题意:给你n个数,分成k个非空集合,其中有p个集合的元素和为偶数,其余k-p个集合的元素和为奇数. 思路: ...
- codeforces 439C Devu and Partitioning of the Array(烦死人的多情况的模拟)
题目 //这是一道有n多情况的烦死人的让我错了n遍的模拟题 #include<iostream> #include<algorithm> #include<stdio.h ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 浪潮云+/云加 App 智能化的企业移动办公平台官网下载地址
上Google?Facebook? 点这里: 手机端:https://ecm.inspur.com/ 桌面端:https://ecm.inspuronline.com/
- windows 服务下搭建jsp运行环境
此处搭建的是运行环境,不是开发环境. 1, 下载sdk 并安装 1.8 http://rj.baidu.com/soft/detail/14459.html?ald 2, 配置环境变量 步 ...
- 深入浅出 Java Concurrency (10): 锁机制 part 5 闭锁 (CountDownLatch)[转]
此小节介绍几个与锁有关的有用工具. 闭锁(Latch) 闭锁(Latch):一种同步方法,可以延迟线程的进度直到线程到达某个终点状态.通俗的讲就是,一个闭锁相当于一扇大门,在大门打开之前所有线程都被阻 ...
- vue 路由 URL传参
源码如下: import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) //全局使用该组件 const ro ...
- String和StringBuffer的区别;字符串的一些基本方法
String 和 StringBuffer区别 字符串广泛应用 在Java 编程中,在 Java 中字符串属于对象,Java 提供了 String 类来创建和操作字符串. 需要注意的是,String的 ...
- Python学习之列表--自动超市购物车
效果图: 实现代码: menu = [0,5000,500,9000,3000,30,50,7000,70,40]name = [0,"iphone","bicycle& ...
- Vue. 之 刷新当前页面,重载页面数据
Vue. 之 刷新当前页面,重载页面数据 如下截图,点击左侧不同的数据,右侧根据左侧的KEY动态加载数据.由于右侧是同一个页面,在进行路由跳转后,不会再次刷新数据. 解决方案: 右侧的页面中 scri ...
- VS2005+VTK读入点云文件
使用VTK读入点云文件的基础代码: 头文件: 也许不是全部都用到,为了接下来得工程还是全部都包含进去了 #include "vtkRenderer.h" #include &quo ...
- Luogu P2764 最小路径覆盖问题(二分图匹配)
P2764 最小路径覆盖问题 题面 题目描述 «问题描述: 给定有向图 \(G=(V,E)\) .设 \(P\) 是 \(G\) 的一个简单路(顶点不相交)的集合.如果 \(V\) 中每个顶点恰好在 ...
- goland设置颜色和字体