1113 Integer Set Partition (25 分)
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1and 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 ∣n1−n2∣ is minimized first, and then ∣S1−S2∣ is maximized.
Input Specification:
Each input file contains one test case. For each case, the first line gives an integer N (2≤N≤105), 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: ∣n1−n2∣ and ∣S1−S2∣, 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
分析:真水题。。。先排序然后砍成两半就可以了
/** * Copyright(c) * All rights reserved. * Author : Mered1th * Date : 2019-02-27-13.43.25 * Description : A1113 */ #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<string> #include<unordered_set> #include<map> #include<vector> #include<set> using namespace std; ; int a[maxn]; int main(){ #ifdef ONLINE_JUDGE #else freopen("1.txt", "r", stdin); #endif ; cin>>n; ;i<n;i++){ scanf("%d",&a[i]); sum+=a[i]; } sort(a,a+n); ,s=; ;i<m;i++){ s+=a[i]; } ==){ printf("0 %d",sum-s-s); } else{ printf("1 %d",sum-s-s); } ; }
1113 Integer Set Partition (25 分)的更多相关文章
- 【PAT甲级】1113 Integer Set Partition (25分)
题意: 输入一个正整数N(2<=N<=1e5),接着输入N个正整数,将这些数字划分为两个不相交的集合,使得他们的元素个数差绝对值最小且元素和差绝对值最大. AAAAAccepted cod ...
- 1113. Integer Set Partition (25)
Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint se ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT 甲级 1113 Integer Set Partition
https://pintia.cn/problem-sets/994805342720868352/problems/994805357258326016 Given a set of N (> ...
- PAT 1113 Integer Set Partition
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint set ...
- 1113 Integer Set Partition
Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets ...
- A1113 | Integer Set Partition (25)
太简单了 #include <stdio.h> #include <memory.h> #include <math.h> #include <string& ...
- PAT1113: Integer Set Partition
1113. Integer Set Partition (25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT_A1113#Integer Set Partition
Source: PAT A1113 Integer Set Partition (25 分) Description: Given a set of N (>) positive integer ...
随机推荐
- java算法大全
题一: /** * 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子, * 小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少对? * 分析: * 第 ...
- require('nw.gui') 失效问题
// gui = global.window.nwDispatcher.requireNwGui() --original // gui = window.require('nw.gui') gui ...
- SWIFT中切換UIContainerView內的Controller
如下,一个UIContainerView内切换两个Controller,当点击登录的时候UIContainerView的视图为LoginController,当点击登记的时候UIContainerVi ...
- magento如何安装语言包
1,先下安装,直接在www.magento.com(搜索chinese)官网获得下载密钥,然后在下载站点输入密钥就可以下载,下载完成后的安装包放到app/local文件夹下即可,到后台刷新一下: 2线 ...
- python可视化爬虫实现“京东试用”批量申请
介绍: 环境:chromedriver 2.41.578700+ selenuim3.14.0 过程: 1.打开京东主页 2.登录京东 3.打开京东试用页面 4.获取商品列表 5.自动申请试用(该商品 ...
- CodeForces - 778C: Peterson Polyglot (启发式合并trie树)
Peterson loves to learn new languages, but his favorite hobby is making new ones. Language is a set ...
- python3 获取当前调用函数名
import sys funcName = sys._getframe().f_back.f_code.co_name #获取调用函数名lineNumber = sys._getframe().f_b ...
- CTF中图片隐藏文件分离方法
CTF中图片隐藏文件分离方法 0x01 分析 这里我们以图片为载体,给了这样的一样图片:2.jpg 首先我们需要对图片进行分析,这里我们需要用到kali里面的一个工具 binwalk ,想要了解这 ...
- 【CQOI2008】中位数
题不难,但是思路有意思,这个是我自己想出来的OvO 原题: 给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b.中位数是指把所有元素从小到大排列后,位于中间的数. n<= ...
- test20190320 全连(fc)
题意 全连(fc) [题目背景] 还记得若干年前那段互相比较<克罗地亚狂想曲>的分数的日子吗? [题目描述] E.Space 喜欢打音游. 但是他技术不好,总是拿不到全连(Full Com ...