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 ...
随机推荐
- 使用MyEclipse将HTML5移动项目迁移到PhoneGap(三)
MyEclipse开年钜惠 在线购买低至75折!立即开抢>> [MyEclipse最新版下载] 三.将图像从HTML5项目复制到PhoneGap项目 1. 在PhoneGap项目的www ...
- Final阶段第1周/共1周 Scrum立会报告+燃尽图 02
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2481] 版本控制:https://git.coding.net/liuyy08 ...
- 2018-2019-2 网络对抗技术 20165202 Exp4 恶意代码分析
博客目录 一.实践目标 二.实践内容 1.系统运行监控 2.恶意软件分析 三.实验步骤 四.基础问题回答 五.遇到的问题及解决 六.实验总结 一.实践目标 监控你自己系统的运行状态,看有没有可疑的程序 ...
- ACCESS表的视图
ACCESS表的视图 点击: 发布日期:2007-8-31 6:37:00 进入论坛 表是关系型数据库的基本结构.在Access中,表是一种关系特定主题的数据集合,如产品.供应商等.为 ...
- UIActivityIndicatorView使用
UIActivityIndicatorView显示一个标准的旋转进度轮,类似网页AJAX加载时的图标. let loadIndicator = UIActivityIndicatorView(fram ...
- NBUT 1219 Time 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Digital clock use 4 digits to express time, each digit ...
- IOC和DI 控制反转和依赖注入
首先要分享的是Iteye的开涛这位技术牛人对Spring框架的IOC的理解,写得非常通俗易懂,以下内容全部来自原文,原文地址:http://jinnianshilongnian.iteye.com/b ...
- (8)propetry装饰器
propetry是一个内置函数,用来将一个功能伪装成一个数据属性 property将一个方法伪装成一个数据属性class People: def __init__(self,name,height,w ...
- Linux下rsync命令使用总结
一.rsync的概述 rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync.rsync是Linux系统下的文件同步和数据传输工具,它采用“rsync” ...
- python 取整
1.向下取整 向下取整直接用内建的 int() 函数即可: >>> a = 3.75 >>> int(a) 3 2.四舍五入 对数字进行四舍五入用 round() ...