PAT甲级——A1113 Integer Set Partition
Given a set of N (>) 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 ∣ 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:
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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, s1 = , s2 = , nMin, sMin;
int main()
{
cin >> n;
vector<int>v(n);
for (int i = ; i < n; ++i)
cin >> v[i];
sort(v.begin(), v.end());
for (int i = ; i < n; ++i)
{
if (i < n / )
s1 += v[i];
else
s2 += v[i];
}
cout << n % << " " << s2 - s1 << endl;
return ;
}
PAT甲级——A1113 Integer Set Partition的更多相关文章
- PAT 甲级 1113 Integer Set Partition
https://pintia.cn/problem-sets/994805342720868352/problems/994805357258326016 Given a set of N (> ...
- PAT甲级1103. Integer Factorization
PAT甲级1103. Integer Factorization 题意: 正整数N的K-P分解是将N写入K个正整数的P次幂的和.你应该写一个程序来找到任何正整数N,K和P的N的K-P分解. 输入规格: ...
- PAT A1113 Integer Set Partition (25 分)——排序题
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint set ...
- A1113. Integer Set Partition
Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint se ...
- PAT甲级——1103 Integer Factorization (DFS)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90574720 1103 Integer Factorizatio ...
- A1113 | Integer Set Partition (25)
太简单了 #include <stdio.h> #include <memory.h> #include <math.h> #include <string& ...
- PAT甲级——A1103 Integer Factorization
The K−P factorization of a positive integer N is to write N as the sum of the P-th power of Kpositiv ...
- PAT甲级1103 Integer Factorization【dfs】【剪枝】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805364711604224 题意: 给定一个数n,要求从1~n中找 ...
- PAT_A1113#Integer Set Partition
Source: PAT A1113 Integer Set Partition (25 分) Description: Given a set of N (>) positive integer ...
随机推荐
- Jenkins忘记 admin 密码
进入 jenkins home(我的是/var/jenkins_home)路径下的users 文件夹 cd /var/jenkins_home/users sudo vim admin/config. ...
- d3操作svg路径动画,及dom移动
图片跟随路径循环运动,dom也跟着路径运动(利用实时获取坐标位置的方法,改变transform) 1,准备路径 a,自己脑补路径 b,在ps上画好,然后在保存成png-24图片,背景透明,在网站htt ...
- 解决 php artisan route:list 报错oauth-private.key文件不存在或不可读的
进入项目根目录命令行执行 php artisan passport:install 然后执行php artisan route:list,会提示 Class App\Http\Controllers\ ...
- pycharm 2020 激活码 破解教程
以下是安装完pycharm后进行破解!! 1.修改hosts,在hosts文件最后添加2行“0.0.0.0 account.jetbrains.com”和“0.0.0.0 www.jetbrain ...
- 酷狗mac版如何新建歌单?酷狗mac版收藏歌单方法
很多朋友们都喜欢使用酷狗音乐听音乐,不过最近有使用酷狗mac音乐播放器的Mac新用户,想要新建歌单收藏歌单,但有不知道如何操作,那么苹果电脑酷狗mac版如何新建歌单收藏歌单呢?针对此问题,本文给大家介 ...
- leetcood学习笔记-108-将有序数组转换为二叉搜索树
---恢复内容开始--- 题目描述: 方法一: class Solution(object): def sortedArrayToBST(self, nums): """ ...
- 自定义类型转换器---转Date类型
在使用springMVC过程中 ,假如页面使用了 <form action="${pageContext.request.contextPath}/user/testDate" ...
- Android中使用占位符
Android中占位符的使用 有些朋友可能会动态的修改Android中strings.xml文件中的值,在这里给大家推荐一种简单的方法. strings.xml中节点是支持占位符的,如下所示: < ...
- bzoj1002题解
[题意分析] 给你一张特殊的,被称为“轮状基”的无向图,求其生成树个数. [解题思路] 引理: 基尔霍夫矩阵: 基尔霍夫矩阵=度数矩阵-邻接矩阵(邻接矩阵权=两点连边数) Matrix-Tree定理: ...
- 在vue中使用handsontable
1.使用npm安装 npm install handsontable @handsontable/vue 2.定义结构 <hot-table :settings="hotSetting ...