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持续性开发教程:用JPA和Spring管理数据(三)
MyEclipse红运年货节 在线购买低至69折!火爆开抢>> [MyEclipse最新版下载] 本教程介绍了MyEclipse中的一些基于JPA / Spring的功能.有关设置JPA项 ...
- Excel根据人名匹配得到编号
操作步骤:输入公式 =IF(COUNTIF($E$2:$E2,$E2)>COUNTIF($B:$B,$E2),"",INDEX(C:C,SMALL(IF($B$1:$B$10 ...
- Express文件上传之Multer
Express文件上传之Multer Multer是一个nodejs中间件,用来处理http提交multipart/form-data,也就是文件上传.它是在busboy的基础上开发的. 在我看来,M ...
- Qt 获取组合键 键盘按住某键 鼠标组合实现
#include "mainwindow.h" #include <QDebug> #include <QKeyEvent> #include <QM ...
- GET_DDL提取建表语句:ddl
创建对象的语句就是了 提取表 set line 200 pages 50000 wrap on long 999999 serveroutput on SQL> select dbms_meta ...
- HAL_RTC_MspInit Msp指代什么?
/********************************************************************************* * HAL_RTC_MspInit ...
- android_serialport_api hacking
/************************************************************************************ * * android_se ...
- dubbo监控工具
现在企业使用dubbo技术太普遍,所以dubbo的监控工具也应运而生,而且还很稳定,他就是一个web项目, 部署起来非常简单,下载个项目war包(dubbo-admin-2.5.4-SNAPSHOT. ...
- 20155229 2016-2017-2 《Java程序设计》第五周学习总结
20155229 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 第八章: Java中所有错误都会被打包为对象. 设计错误对象都继承自java.lang.Th ...
- Java-JDK & Android SDK下载安装及配置教程
转自:http://blog.csdn.net/dr_neo/article/details/49870587 第一步.安装JDK: 第二步.安装Eclipse: 第三步.下载并安装AndroidSD ...