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

    https://pintia.cn/problem-sets/994805342720868352/problems/994805357258326016

    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 N positive 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

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 1e5 + 10;
    int N;
    int num[maxn];
    
    int main() {
        scanf("%d", &N);
        int sum = 0;
        for(int i = 0; i < N; i ++) {
            scanf("%d", &num[i]);
            sum += num[i];
        }
    
        sort(num, num + N);
        int ans = 0;
        for(int i = 0; i < N / 2; i ++)
            ans += num[i];
    
        printf("%d %d
    ", N % 2, sum - 2 * ans);
        return 0;
    }
    

      好久不写手生生 今天是 Be 主决心减肥的第一天  

     

  • 相关阅读:
    杭电OJ 输入输出练习汇总
    七月读书笔记
    情报分析报告阅读笔记
    情报研究与分析入门阅读笔记
    旁观者攻击
    域前置技术相关学习
    CC攻击和C2的区别
    DNS投毒学习分析总结
    数字证书2.0版本学习总结
    《在树洞里》-感悟
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/10301181.html
Copyright © 2011-2022 走看看