题意:给你n个数,然后分成k部分,每一个部分的和为偶数的有p个,奇数的有k-p个,如果可以划分,输出其中的一种,不可以输出NO;

思路:先输出k-p-1个奇数,再输出p-1个偶数,剩余的在进行构造。  奇数+奇数=偶数。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #define maxn 1000100
  7. #define ll long long
  8. using namespace std;
  9.  
  10. int n,k,p;
  11. ll a[maxn];
  12. vector<int>qq;
  13. vector<int>pp;
  14.  
  15. int main()
  16. {
  17. scanf("%d%d%d",&n,&k,&p);
  18. for(int i=; i<=n; i++)
  19. {
  20. scanf("%lld",&a[i]);
  21. if(a[i]%==) qq.push_back(a[i]);
  22. else if(a[i]%!=) pp.push_back(a[i]);
  23. }
  24. int odd=pp.size();
  25. int even=qq.size();
  26. if(odd<k-p||(odd>=k-p&&even+(odd-(k-p))/<p)||(odd-(k-p))%==)
  27. printf("NO\n");
  28. else
  29. {
  30. printf("YES\n");
  31. for(int i=; i<k-p-; i++)
  32. {
  33. printf("%d %d\n",,pp[i]);
  34. }
  35. int x=k-p-;
  36. int y=even;
  37. if(x<)x=;
  38. for(int i=; i<p-; i++)
  39. {
  40. if(y)
  41. {
  42. printf("%d %d\n",,qq[y-]);
  43. y--;
  44. }
  45. else
  46. {
  47. printf("%d %d %d\n",,pp[x],pp[x+]);
  48. x+=;
  49. }
  50. }
  51. if(k-p!=&&p)
  52. {
  53. printf("%d %d\n",,pp[x]);
  54. x++;
  55. }
  56. if(x<) x=;
  57. printf("%d ",y+odd-x);
  58. while(y)
  59. {
  60. printf("%d ",qq[y-]);
  61. y--;
  62. }
  63. while(x<odd)
  64. {
  65. printf("%d ",pp[x]);
  66. x++;
  67. }
  68. printf("\n");
  69. }
  70. return ;
  71. }

codeforces C. Devu and Partitioning of the Array的更多相关文章

  1. Codeforces 439C Devu and Partitioning of the Array(模拟)

    题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数 ...

  2. codeforces 439D Devu and Partitioning of the Array(有深度的模拟)

    题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一 ...

  3. codeforces 439C Devu and Partitioning of the Array(烦死人的多情况的模拟)

    题目 //这是一道有n多情况的烦死人的让我错了n遍的模拟题 #include<iostream> #include<algorithm> #include<stdio.h ...

  4. codeforces 251 div2 C. Devu and Partitioning of the Array 模拟

    C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...

  5. 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 ...

  6. CF 439C Devu and Partitioning of the Array

    题目链接: 传送门 Devu and Partitioning of the Array time limit per test:1 second     memory limit per test: ...

  7. 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 ...

  8. Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array

    注意p的边界情况,p为0,或者 p为k 奇数+偶数 = 奇数 奇数+奇数 = 偶数 #include <iostream> #include <vector> #include ...

  9. 【Henu ACM Round#20 D】 Devu and Partitioning of the Array

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一开始所有的数字单独成一个集合. 然后用v[0]和v[1]记录集合的和为偶数和奇数的集合它们的根节点(并查集 然后先让v[0]的大小 ...

随机推荐

  1. 网络子系统43_ip选项预处理

    //选项格式: // 1.type中指示该选项在分片时是否需要被拷贝 // 2.ptr从1算起,1为type的位置 // 3.len不包括type字段,其余都包括(len,ptr,选项内容) //ty ...

  2. [Javascript] Modifying an Immutable.js Map()

    We will now look at five methods that modify an Immutable.Map(). set update delete clear merge //set ...

  3. Android自定义drawable(Shape)详解

    在Android开发过程中,经常需要改变控件的默认样式, 那么通常会使用多个图片来解决.不过这种方式可能需要多个图片,比如一个按钮,需要点击时的式样图片,默认的式样图片. 这样就容易使apk变大. 那 ...

  4. 如何设计一个简单的C++ ORM

    2016/11/15 "没有好的接口,用C++读写数据库和写图形界面一样痛苦" 阅读这篇文章前,你最好知道什么是 Object Relation Mapping (ORM) 阅读这 ...

  5. xslt语法之---position()函数

    最近在学习使用XSLT,很好很强大的样式表语言.使用到了position()函数特此记录一下. position()函数--返回节点位置 语法:position() 参数:无 返回值:整数 用途:该函 ...

  6. css考核点整理(三)-css选择器的使用

    css选择器的使用

  7. sublime的js调试环境(基于node环境)

    很多的语言都有控制台,都要专门的ide,js,用sublime在node的环境下,可以配置console, 如何配置?首先,要有node的环境,下载安装,还要安装到c盘才行,然后找到'工具(tool) ...

  8. try{}catch(){}//根据异常信息使用不同的方法要怎么实现

    try{ }catch(Exception e){ if(e.getMessage().contains("123456798")) //使用e.getMessage().cont ...

  9. windows Server 2008 -必须使用“角色管理工具”安装或配置Microsoft .Net Framework 3.5

    在windows Server 2008上安装 .Net Framework 3.5的时候,报错:必须使用“角色管理工具”安装或配置Microsoft .Net Framework 3.5. Solu ...

  10. eclipse中修改内存