zoukankan      html  css  js  c++  java
  • PAT甲级——A1113 Integer Set Partition

    Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets A1​​ and A2​​ of n1​​and n2​​ numbers, respectively. Let S1​​ and S2​​ denote the sums of all the numbers in A1​​ and A2​​, respectively. You are supposed to make the partition so that ∣ is minimized first, and then ∣ is maximized.

    Input Specification:

    Each input file contains one test case. For each case, the first line gives an integer N (2), and then Npositive integers follow in the next line, separated by spaces. It is guaranteed that all the integers and their sum are less than 231​​.

    Output Specification:

    For each case, print in a line two numbers: ∣ and ∣, separated by exactly one space.

    Sample Input 1:

    10
    23 8 10 99 46 2333 46 1 666 555
    

    Sample Output 1:

    0 3611
    

    Sample Input 2:

    13
    110 79 218 69 3721 100 29 135 2 6 13 5188 85
    

    Sample Output 2:

    1 9359

    一句话,弱智题
     1 #include <iostream>
     2 #include <vector>
     3 #include <algorithm>
     4 using namespace std;
     5 int n, s1 = 0, s2 = 0, nMin, sMin;
     6 int main()
     7 {
     8     cin >> n;
     9     vector<int>v(n);
    10     for (int i = 0; i < n; ++i)
    11         cin >> v[i];
    12     sort(v.begin(), v.end());
    13     for (int i = 0; i < n; ++i)
    14     {
    15         if (i < n / 2)
    16             s1 += v[i];
    17         else
    18             s2 += v[i];
    19     }
    20     cout << n % 2 << " " << s2 - s1 << endl;
    21     return 0;
    22 }
  • 相关阅读:
    [视频监控]用状态机图展示Layout切换关系
    初次打开mysql5.6后
    eclipse 项目乱码
    java servlet 中遇到的编码问题
    解决HttpServletResponse输出的中文乱码问题
    The first day of my Blog
    最大子段和
    LOI 54 成立一周年纪(zuo)念(si)
    水题 逆序对 NOIP 2013 火柴排队
    搜索 由浅入深 之一 水题
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11455588.html
Copyright © 2011-2022 走看看