博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT甲级——A1113 Integer Set Partition
阅读量:4541 次
发布时间:2019-06-08

本文共 1430 字,大约阅读时间需要 4 分钟。

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:

1023 8 10 99 46 2333 46 1 666 555

Sample Output 1:

0 3611

Sample Input 2:

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

Sample Output 2:

1 9359 一句话,弱智题
1 #include 
2 #include
3 #include
4 using namespace std; 5 int n, s1 = 0, s2 = 0, nMin, sMin; 6 int main() 7 { 8 cin >> n; 9 vector
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 else18 s2 += v[i];19 }20 cout << n % 2 << " " << s2 - s1 << endl;21 return 0;22 }

 

转载于:https://www.cnblogs.com/zzw1024/p/11455588.html

你可能感兴趣的文章
目录的创建,删除,获取当前目录
查看>>
软件体系结构原理、方法与实践总结
查看>>
数字排序转变为字母排序
查看>>
2017-2018-1 《程序设计与数据结构》第3周学习总结
查看>>
C++ stringstream介绍,使用方法与例子
查看>>
android 系统目录及adb
查看>>
Hibernate入门
查看>>
sql语法:从一个表update到另外一个表
查看>>
HashMap学习总结
查看>>
十三,权限
查看>>
判断两个线段是否相交
查看>>
一些基础语法
查看>>
360多万条信息把一台服务器快拖卡了
查看>>
Git详解之六 Git工具
查看>>
等高布局display:table
查看>>
onunload与onbeforeunload事件解析 ...
查看>>
Openjudge-计算概论(A)-取石子游戏
查看>>
python-装饰器
查看>>
(4)获取servlet常用api
查看>>
[f]区间随机数函数
查看>>