codeforces 251 div2 C. Devu and Partitioning of the Array 模拟
1 second
256 megabytes
standard input
standard output
Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him?
Given an array consisting of distinct integers. Is it possible to partition the whole array into k disjoint non-empty parts such that p of the parts have even sum (each of them must have even sum) and remaining k - p have odd sum? (note that parts need not to be continuous).
If it is possible to partition the array, also give any possible way of valid partitioning.
The first line will contain three space separated integers n, k, p (1 ≤ k ≤ n ≤ 105; 0 ≤ p ≤ k). The next line will contain n space-separated distinct integers representing the content of array a: a1, a2, ..., an (1 ≤ ai ≤ 109).
In the first line print "YES" (without the quotes) if it is possible to partition the array in the required way. Otherwise print "NO" (without the quotes).
If the required partition exists, print k lines after the first line. The ith of them should contain the content of the ith part. Print the content of the part in the line in the following way: firstly print the number of elements of the part, then print all the elements of the part in arbitrary order. There must be exactly p parts with even sum, each of the remaining k - p parts must have odd sum.
As there can be multiple partitions, you are allowed to print any valid partition.
5 5 3
2 6 10 5 9
YES
1 9
1 5
1 10
1 6
1 2
5 5 3
7 14 2 9 5
NO
5 3 1
1 2 3 7 5
YES
3 5 1 3
1 7
1 2
题意:给你n个数,分成m堆,这些堆的和为偶数的堆为p堆;
思路:分析清楚情况就是,偶数永远是偶数,但是两个奇数可以组成一个偶数;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 1000000007
#define inf 999999999
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int even[],ji;
int odd[],ou;
int main()
{
int x,y,z,i,t;
int n,k,p;
scanf("%d%d%d",&n,&k,&p);
for(i=;i<n;i++)
{
scanf("%d",&z);
if(z&)
even[ji++]=z;
else
odd[ou++]=z;
}
if(ji<k-p||(ji-k+p)&)
{
printf("NO\n");
return ;
}
else
{
if(ou+(ji-k+p)/<p)
{
printf("NO\n");
return ;
}
else
{
printf("YES\n");
if(p==)
{
for(i=;i<k-p-;i++)
printf("1 %d\n",even[i]);
printf("%d",ji-k++ou);
for(i=k-p-;i<ji;i++)
printf(" %d",even[i]);
for(i=;i<ou;i++)
printf(" %d",odd[i]);
printf("\n");
}
else if(ou<p)
{
int fuck=k-p;
for(i=;i<k-p;i++)
printf("1 %d\n",even[i]);
for(i=;i<ou;i++)
printf("1 %d\n",odd[i]);
for(i=;i<p-ou-;i++)
printf("2 %d %d\n",even[fuck++],even[fuck++]);
printf("%d",ji-fuck);
for(i=fuck;i<ji;i++)
printf(" %d",even[i]);
printf("\n");
}
else
{
for(i=;i<k-p;i++)
printf("1 %d\n",even[i]);
for(i=;i<p-;i++)
printf("1 %d\n",odd[i]);
printf("%d",n-k+);
for(i=k-p;i<ji;i++)
printf(" %d",even[i]);
for(i=p-;i<ou;i++)
printf(" %d",odd[i]);
printf("\n");
}
}
}
return ;
}
codeforces 251 div2 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 251 div2 D. Devu and his Brother 三分
D. Devu and his Brother time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 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 ...
- 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 C. Devu and Partitioning of the Array
题意:给你n个数,然后分成k部分,每一个部分的和为偶数的有p个,奇数的有k-p个,如果可以划分,输出其中的一种,不可以输出NO; 思路:先输出k-p-1个奇数,再输出p-1个偶数,剩余的在进行构造. ...
随机推荐
- 版本 ------- 2017年最受开发者欢迎的10个Linux发行版
1.Arch Linux Arch Linux在安装过程中提供了强大的可定制选择,支持你下载和安装自己所需的程序包.虽然这个选择对新手来说没有多大的帮助,但是它确实能够帮助那些使用Arch构建系统和存 ...
- hdu1305Immediate Decodability(字典树)
这题看是否 这题能A是侥幸,解决的办法是先存一下输入的字符串,进行排序. Problem Description An encoding of a set of symbols is said to ...
- [lr] 基本色调调整和色调曲线
基本色调调整 • 曝光度调整 ▶ 控制区域 在Lightroom中,软件提示我们曝光控制的是如图中间调的区域.我们把鼠标移动到曝光工具条上,软件会提示我们这个区域: ▶ 实际效果 ▪ 增加曝光值 增加 ...
- 浅谈Android View滑动冲突
引言 上一篇文章我们从源码的角度介绍了View事件分发机制,这一篇文章我们就通过介绍滑动冲突的规则和一个实例来更加深入的学习View的事件分发机制. 1.外部滑动方向和内部滑动方向不一致 考虑这样一种 ...
- HTML鼠标悬停改变样式
a.tt:hover {color: #FF0000;} <a class="tt" href="test.html">test</a> ...
- php mysql_connect pmysql_connect区别
<?php mysql_pconnect('192.168.75.128', 'root', 'root'); mysql_close(); sleep ...
- 用python实现一个简单的socket网络聊天通讯 (Linux --py2.7平台与windows--py3.6平台)
windows --> windows 写法均在py3.6 客户端写法 import socket client = socket.socket() client.connect(('192 ...
- 利用js添加class
来来来,开篇点题. 分页应用.当在当前页时,分页的数字有个框之类的. 重要代码如下 <ul class="pagination"> <li><a hr ...
- codeforces E - Anya and Cubes 分块处理 暴力搜索
说的是给了n个立方体,立方体从1标号到n,每个立方体上有一个数字, 你有 k 个机会 使得其中 k个数位他们自己的阶乘,(自然使用可以少于k次机会,每个立方体最多被使用1次) ,那么求出你从这n个立方 ...
- Java: war包的作用及使用方法,如何解压后缀名为war的文件
1.什么是war文件? 如果一个Web应用程序的目录和文件非常多,那么将这个Web应用程序部署到另一台机器上,就不是很方便了,我们可以将Web应用程序打包成Web归档(WAR)文件.这个过程和把Jav ...