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 S2denote 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", N % 2, sum - 2 * ans);
return 0;
}
好久不写手生生 今天是 Be 主决心减肥的第一天
PAT 甲级 1113 Integer Set Partition的更多相关文章
- PAT甲级——A1113 Integer Set Partition
Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets ...
- 1113 Integer Set Partition (25 分)
1113 Integer Set Partition (25 分) Given a set of N (>1) positive integers, you are supposed to pa ...
- PAT甲级1103. Integer Factorization
PAT甲级1103. Integer Factorization 题意: 正整数N的K-P分解是将N写入K个正整数的P次幂的和.你应该写一个程序来找到任何正整数N,K和P的N的K-P分解. 输入规格: ...
- 【PAT甲级】1113 Integer Set Partition (25分)
题意: 输入一个正整数N(2<=N<=1e5),接着输入N个正整数,将这些数字划分为两个不相交的集合,使得他们的元素个数差绝对值最小且元素和差绝对值最大. AAAAAccepted cod ...
- PAT 1113 Integer Set Partition
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint set ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 1113. Integer Set Partition (25)
Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint se ...
- 1113 Integer Set Partition
Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets ...
- PAT甲级——1103 Integer Factorization (DFS)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90574720 1103 Integer Factorizatio ...
随机推荐
- 【转载】COM 组件设计与应用(十五)——连接点(vc6.0)
原文:http://vckbase.com/index.php/wv/1256.html 一.前言 上回书介绍了回调接口,在此基础上,我们理解连接点就容易多了. 二.原理 图一.连接点组件原理图.左侧 ...
- $anchorScroll angular锚点服务
angular锚点服务 $anchorScroll 普通的html页面中,我们会通过在url后面添加#elementId的方式,将页面显示定位到某个元素上,也就是所谓的锚点. 但是在angular应用 ...
- pymysql模块使用教程
一.操作数据库模板 pymysql是Python中操作mysql的模块,(使用方法几乎和MySQLdb相同,但是在Python3中,mysqldb这个库已经不能继续使用了) 下载安装方法: 方法一. ...
- <link rel="stylesheet" type="text/css" href="css/index.css">详解
整条语句的含义是: 调用一个外部的CSS样式文件.他是通过<link/>这个标签来调用的. 然后, href="css/index.css" 表示外部样式文件的路径, ...
- Qt-网易云音乐界面实现-5 收藏列表,播放列表实现 QListWidget QTableWidget
先上目前完成的内容吧,发现后面越写越多.在看看点击量,心凉凉. 完成了左侧的导航列表,还有就是右下角的播放列表. //创建的歌单 my_Create_Music_List = new QListWid ...
- 通过ftp同步服务器文件:遍历文件夹所有文件(含子文件夹、进度条);简单http同步服务器文件实例
该代码主要实现,指定ftp服务地址,遍历下载该地址下所有文件(含子文件夹下文件),并提供进度条显示:另外附带有通过http地址方式获取服务器文件的简单实例 废话不多说,直接上代码: 1.FTPHelp ...
- 执行caffe的draw_net.py出现“GraphViz's executable "dot" not found”的解决方法
控制台输入如下指令画网络图: python ../../../python/draw_net.py train.prototxt train.png --rankdir=TB (Top-Bottom形 ...
- Unity3d — — UGUI之Box Collider自适应大小
NGUI下给Sprite/image添加collider后能自适应大小,但是在UGUI下Collider是默认在(0,0)位置,size为0 因此写了个简单的脚本,效果如下(最后附代码) 1.如下图添 ...
- 廖雪峰git教程学习笔记
对git来说,没有消息就是最好的消息 使用 git init 把当前目录变为git仓库 要在仓库里加入文件,先在仓库目录新建这个文件后,比如新建一个文件xiaobai.txt,内容为: 在命令行里输入 ...
- js数组知识点总结及经典笔试题
1.判断数组 这是笔试里经常会出现的知识考察点,总结一下 (1)Array.isArray()方法判断 var a=[]; Array.isArray(a) //返回true var b='hello ...